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

CF920F SUM and REPLACE 线段树的更多相关文章

  1. 【Educational Codeforces Round 37】F. SUM and REPLACE 线段树+线性筛

    题意 给定序列$a_n$,每次将$[L,R]$区间内的数$a_i$替换为$d(a_i)$,或者询问区间和 这题和区间开方有相同的操作 对于$a_i \in (1,10^6)$,$10$次$d(a_i) ...

  2. codeforces 1217E E. Sum Queries? (线段树

    codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...

  3. Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树

    题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...

  4. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...

  5. 【BZOJ4262】Sum 单调栈+线段树

    [BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...

  6. CF1217E Sum Queries? (线段树)

    完了,前几天才说 edu 的 DEF 都不会,现在打脸了吧 qwq 其实在刚说完这句话 1min 就会了 D,3min 就会了 E 发现,对于大小 \(\ge 3\) 的不平衡集合,它至少有一个大小为 ...

  7. codeforces 85D D. Sum of Medians 线段树

    D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

  8. leetcode@ [307] Range Sum Query - Mutable / 线段树模板

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [tem]线段树练习

    1080 线段树练习 单点修改,区间查询和 #include <iostream> #include <cstdio> #include <algorithm> # ...

随机推荐

  1. 通过阿里云域名动态解析 IP 地址

    这两天在家里用树莓派折腾了一个家用服务器,主要用来做 mac 的 Time Machine ,还有就是当做下载机和 nas ,想着平时上班时间家里没人用网络,空着也是空着,就可以利用空闲带宽下个美剧啥 ...

  2. 清除float浮动三种方式

    Float的作用? w3c的官方解释: Content flows down the right side of a left-floated box and down the left side o ...

  3. 【C】四则运算生成和核对器----by郁卓、谢明浩

    [Github项目地址] 完成功能: 1. 使用 -n 参数控制生成题目的个数 2. 使用 -r 参数控制题目中数值(自然数.真分数和真分数分母)的范围 3. 生成的题目中计算过程不能产生负数,也就是 ...

  4. (转)C/C++——auto,static,register,extern用法

    转自:https://blog.csdn.net/u010757264/article/details/49932829 C++中变量.函数的属性包括数据类型和存储类别.存储类别分为静态存储和动态存储 ...

  5. Python实现排序算法之快速排序

    Python实现排序算法:快速排序.冒泡排序.插入排序.选择排序.堆排序.归并排序和希尔排序 Python实现快速排序 原理 首先选取任意一个数据(通常选取数组的第一个数)作为关键数据,然后将所有比它 ...

  6. MySQL整体架构与内存结构

    一  mysql 整体框架: MySQL是由SQL接口,解析器,优化器,缓存,存储引擎等组成的. 1. Connectors指的是不同语言中与SQL的交互. 2. Management Serveic ...

  7. IHE-PIX 备注

    IHE给出了各个Actor之间如何通讯的建议: 1.       应用程序通讯时必须用MLLP包装或者解析. 2.       客户端建立连接后,服务器端必须用此连接进行应答.客户端可以继续用此连接启 ...

  8. 用OpenLayers开发地图应用

    项目背景 最近有一个使用全球地图展示数据的项目,用地图展示数据本身没什么难度,但出于安全和保密的考虑,甲方单位要求项目不能连接外网,只能在内网使用,也就是说,我们不得不在内网中部署一个地图服务器,在这 ...

  9. <正则吃饺子> :关于微信支付的简单总结说明(二)

    关于微信退款 一.官方文档 申请退款:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 二.退款流程 ...

  10. JAVA类型信息——Class对象(转载)

    JAVA类型信息--Class对象 一.RTTI概要 1.类型信息RTTI :即对象和类的信息,例如类的名字.继承的基类.实现的接口等. 2.类型信息的作用:程序员可以在程序运行时发现和使用类型信息. ...