CF920F SUM and REPLACE 线段树
2024-09-07 01:19:18
给你一个数组a_i,D(x)为x的约数个数
两种操作:
1.将[l,r]的a_i替换为D(a_i)
2.输出∑a_i ( l <= i <= r )
当区间最大值<=2时,就不会被修改了,因为d(2)=2,d(1)=1。
#include<cstdio>
#include<iostream>
#define R register int
#define ls (tr<<1)
#define rs (tr<<1|1)
const int M=;
using namespace std;
inline long long g() {
register long long ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
int n,m;
long long sum[],mx[],cnt[];
inline void upd(int tr) {sum[tr]=sum[ls]+sum[rs]; mx[tr]=max(mx[ls],mx[rs]);}
inline void calc() {for(R i=;i<=M;++i) for(R j=;i*j<=M;++j) ++cnt[i*j];}
inline void build(int tr,int l,int r) {
if(l==r) {mx[tr]=sum[tr]=g(); return ;}
R md=(l+r)>>; build(ls,l,md),build(rs,md+,r); upd(tr);
}
inline void change(int tr,int l,int r,int LL,int RR) {
if(mx[tr]<=) return ;
if(l==r) {sum[tr]=mx[tr]=cnt[sum[tr]]; return ;}
R md=(l+r)>>;
if(LL>md) change(rs,md+,r,LL,RR);
else if(RR<md+) change(ls,l,md,LL,RR);
else change(ls,l,md,LL,md),change(rs,md+,r,md+,RR); upd(tr);
}
inline long long query(int tr,int l,int r,int LL,int RR) {
if(l==LL&&r==RR) return sum[tr];
R md=(l+r)>>;
if(LL>md) return query(rs,md+,r,LL,RR);
else if(RR<md+) return query(ls,l,md,LL,RR);
else return query(ls,l,md,LL,md)+query(rs,md+,r,md+,RR);
}
signed main() {
n=g(),m=g(); calc(); build(,,n);
for(R i=,k,l,r;i<=m;++i) {
k=g(),l=g(),r=g();
if(k==) change(,,n,l,r);
else printf("%lld\n",query(,,n,l,r));
}
}
2019.04.18
最新文章
- SimpleSSO:使用Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端
- OJ生成器(一)制作Online Judge前的准备和策划
- IO流03--毕向东JAVA基础教程视频学习笔记
- iOS,Xcode7 制作Framework,含资源和界面
- hashmap和hashtable,arraylist和vector的区别
- for in
- IOS学习笔记38--@class #import辨析 #include
- C++类的数组元素查找最大值问题
- 修改UITextfield的Placeholder字体的颜色
- diffuse linux 文件比对工具
- 【IOS学习基础】归档和解档
- This exception may occur if matchers are combined with raw values
- digitalocean教程:你应该知道的10件事
- Mac从零配置Vim
- Django 提交 form 表单(使用sqlite3保存数据)
- GGTalk即时通讯系统(支持广域网)终于有移动端了!(技术原理、实现、源码)
- Asp.net core 学习笔记 ( ViewComponent 组件 )
- 【IDEA】【4】遇到的问题
- shell日常实战练习——通过监视用户登陆找到入侵者
- Ansible 入门指南 - ansible-playbook 命令