CF920F SUM and REPLACE 线段树
给你一个数组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 线段树的更多相关文章
- 【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) ...
- codeforces 1217E E. Sum Queries? (线段树
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 ...
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
- 【BZOJ4262】Sum 单调栈+线段树
[BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...
- CF1217E Sum Queries? (线段树)
完了,前几天才说 edu 的 DEF 都不会,现在打脸了吧 qwq 其实在刚说完这句话 1min 就会了 D,3min 就会了 E 发现,对于大小 \(\ge 3\) 的不平衡集合,它至少有一个大小为 ...
- 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 ...
- 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 ...
- [tem]线段树练习
1080 线段树练习 单点修改,区间查询和 #include <iostream> #include <cstdio> #include <algorithm> # ...
随机推荐
- java--List判断是否为空
list.isEmpty()和list.size()==0 没有区别 isEmpty()判断有没有元素,size()返回元素个数 如果判断一个集合有无元素,用isEmpty()方法. 这就相当与,你要 ...
- 如何快速批量修改ArcGIS中的图层设置
在ArcGIS中作图的时候,我们通常需要设置图层的颜色和粗细.点击图层的颜色,会跳出以下符号选择器: 右侧即可修改我们需要的属性. 但是我们有多个类似的属性如何修改成统一的样式呢? 鼠标图层右键,选择 ...
- phpstorm 2016.3.2 的最新破解方法(截止2017-2-20)
最新更新 ,http://idea.imsxm.com 这个地址是亲测可用的,针对最新的phpstorm 2016.3.2的版本.使用方式和下面一致,选择license server.然后复制http ...
- python 案例之老王开枪
- BZOJ_3550_[ONTAK2010]Vacation&&BZOJ_1283:_序列_网络流解线性规划
BZOJ_3550_[ONTAK2010]Vacation&&BZOJ_1283:_序列_网络流解线性规划 Description 给出一个长度为 的正整数序列Ci,求一个子序列,使得 ...
- 「SHOI2002」「LuoguP1291」百事世界杯之旅(UVA10288 Coupons)(期望,输出
题目描述 “……在2002年6月之前购买的百事任何饮料的瓶盖上都会有一个百事球星的名字.只要凑齐所有百事球星的名字,就可参加百事世界杯之旅的抽奖活动,获得球星背包,随声听,更克赴日韩观看世界杯.还不赶 ...
- pycharm+QT5+python3安装与环境配置
开发环境: MAC OS 10.12.3 版本 Pycharm 2016.3.2 版本 Python 3.6.0 版本 PyQt5 5.8.1 版本 ( pyinstaller:将python代 ...
- OGG 进程清除、重建
背景描述:有时候OGG进程同步出现问题,症状某些进程起不来,而且问题一时半会儿解决不了.最简单的办法是:用数据泵初始化数据,OGG进程重建. 1.查看源端.目的端的进程状态. (作者OGG进程是正常的 ...
- bzoj1072Perm——状压DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1072 数字串最多只有10位,所以考虑用状压: 压缩的状态是哪些数字被用过,这样可以从一种状态 ...
- MQTT 客户端源码分析
参看:逍遥子_mosquitto源码分析系列 参看:MQTT libmosquitto源码分析 参看:Mosquitto学习笔记 一.目录结构 首先我们还是来看一下 mosquitto-1.4.14 ...