给你一个数组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

最新文章

  1. SimpleSSO:使用Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端
  2. OJ生成器(一)制作Online Judge前的准备和策划
  3. IO流03--毕向东JAVA基础教程视频学习笔记
  4. iOS,Xcode7 制作Framework,含资源和界面
  5. hashmap和hashtable,arraylist和vector的区别
  6. for in
  7. IOS学习笔记38--@class #import辨析 #include
  8. C++类的数组元素查找最大值问题
  9. 修改UITextfield的Placeholder字体的颜色
  10. diffuse linux 文件比对工具
  11. 【IOS学习基础】归档和解档
  12. This exception may occur if matchers are combined with raw values
  13. digitalocean教程:你应该知道的10件事
  14. Mac从零配置Vim
  15. Django 提交 form 表单(使用sqlite3保存数据)
  16. GGTalk即时通讯系统(支持广域网)终于有移动端了!(技术原理、实现、源码)
  17. Asp.net core 学习笔记 ( ViewComponent 组件 )
  18. 【IDEA】【4】遇到的问题
  19. shell日常实战练习——通过监视用户登陆找到入侵者
  20. Ansible 入门指南 - ansible-playbook 命令

热门文章

  1. Object.is() Pollyfill
  2. POJ 2497 Strategies
  3. 1034 Head of a Gang (30)(30 分)
  4. ACM学习历程—HDU1028 Ignatius and the Princess(组合数学)
  5. 洛谷 2577 [ZJOI2005]午餐——序列dp
  6. Vijos:P1117数的划分
  7. Hadoop——hive安装
  8. Oracle的rowid
  9. mvvm 模板中事件没有执行的解决方案
  10. 【转】eclipse修改workspace