HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)
Naive Operations
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Others)
Total Submission(s): 887 Accepted Submission(s): 336
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
For each test case, in the first line, two integers n,q, representing the length of a,b and the number of queries.
In the second line, n integers separated by spaces, representing permutation b.
In the following q lines, each line is either in the form 'add l r' or 'query l r', representing an operation.
1≤n,q≤100000, 1≤l≤r≤n, there're no more than 5 test cases.
1 5 2 4 3
add 1 4
query 1 4
add 2 5
query 2 5
add 3 5
query 1 5
add 2 4
query 1 4
add 2 5
query 2 5
add 2 2
query 1 5
#include<bits/stdc++.h> using namespace std; #define ls (id<<1)
#define rs ((id<<1)|1)
#define mid ((l+r)>>1)
typedef long long LL; const int maxn=+;
int n,q;
int b[maxn];
struct Node{ int mina;
int valb;
int zero_sum;
int id;
int lazy; }node[maxn<<];
void pushdown(int id,int l,int r){//往下更新
node[ls].lazy+=node[id].lazy;
node[rs].lazy+=node[id].lazy;
node[ls].mina-=node[id].lazy;
node[rs].mina-=node[id].lazy;
node[id].lazy=;
}
void pushup(int id,int l,int r){//往上更新
node[id].zero_sum=node[ls].zero_sum+node[rs].zero_sum;
node[id].mina=min(node[ls].mina,node[rs].mina);
}
void build(int l,int r,int id){
node[id].zero_sum=node[id].lazy=;
if(l==r){ node[id].valb=node[id].mina=b[l];
//cout<<"id=="<<id<<" l=="<<l<<" r=="<<r<<"node[id].mina="<<node[id].mina<<endl;
return;
}
build(l,mid,ls);
build(mid+,r,rs);
pushup(id,l,r);
}
void update(int l,int r,int id,int ql,int qr){
//cout<<"id=="<<id<<" l=="<<l<<" r=="<<r<<"node[id].mina="<<node[id].mina<<endl;
if(l>r)return;
if(node[id].mina>&&ql<=l&&qr>=r){///到时候修改一下!!有包含的区间并且不存在要为0的叶子节点;
node[id].lazy++;
node[id].mina--;
return;
}
if(l==r&&node[id].mina==){//正好整除的叶子节点
node[id].zero_sum++;
node[id].lazy=;
node[id].mina=node[id].valb;
return;
}
if(node[id].lazy)pushdown(id,l,r);
if(qr<=mid)update(l,mid,ls,ql,qr);
else if(ql>mid)update(mid+,r,rs,ql,qr);
else{
update(l,mid,ls,ql,qr);
update(mid+,r,rs,ql,qr);
}
pushup(id,l,r);
}
int query(int l,int r,int id,int ql,int qr){
// cout<<"id=="<<id<<" l=="<<l<<" r=="<<r<<"node[id].mina="<<node[id].mina<<endl;
if(l>r)return ;
if(ql<=l&&r<=qr)return node[id].zero_sum;//被需要查询包含的区间;
/*if (node[id].mina <= 0) {
update(1, 1, n, ql, qr);
}*/
if(qr<=mid)return query(l,mid,ls,ql,qr);
else if(ql>mid)return query(mid+,r,rs,ql,qr);
else{
return query(l,mid,ls,ql,qr)+query(mid+,r,rs,ql,qr);
}
}
int main()
{
std::ios::sync_with_stdio(false);
while(cin>>n>>q){
for(int i=;i<=n;i++)cin>>b[i];
build(,n,);
while(q--){
char s[];
int ll,rr;
cin>>s>>ll>>rr;
if(s[]=='a')update(,n,,ll,rr);
else
cout<<query(,n,,ll,rr)<<endl;
}
}
return ;
}
HDU-6315 Naive Operations//2018 Multi-University Training Contest 2___1007 (线段树,区间除法)的更多相关文章
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU 6315: Naive Operations
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树
hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
- HDU - 6315 Naive Operations (线段树+思维) 2018 Multi-University Training Contest 2
题意:数量为N的序列a和b,a初始全为0,b为给定的1-N的排列.有两种操作:1.将a序列区间[L,R]中的数全部+1:2.查询区间[L,R]中的 ∑⌊ai/bi⌋(向下取整) 分析:对于一个位置i, ...
- HDU 6315 Naive Operations(线段树+区间维护)多校题解
题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...
- HDU 6315 Naive Operations(线段树+复杂度均摊)
发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...
随机推荐
- Percona-Tookit工具包之pt-heartbeat
Preface Replication delay is a common issue in MySQL replications.Especially in those replic ...
- appium-在页面点击一下处理(一般处理提示蒙层)
在写用例的时候,经常会发现某些第一次进去的页面会有一个蒙层提示.我们只有处理掉这个蒙层,才能继续我们的用例: 这边我们使用的是TouchAction的tap方法 TouchAction action ...
- ctags+cscope替换sourceinsight
背景 windows环境开发+linux交叉编译的开发模式,代码阅读和编写都用的source-insight. 除了检索,跳转,工程构建等方面,sourceinsight自带了一些宏语言,可以轻松实现 ...
- 聊聊、Mybatis Java注解实现
AbstractAnnotationConfigDispatcherServletInitializer public class MvcInitializer extends AbstractAnn ...
- vue实现数据的增删改查
在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的用户列表里,我们可以录入新用户的信息,也可以对既有的用户信息进行修改.在vue中,我们更应该专注 ...
- restorator 运行后其他所有EXE文件都无法运行的解决方案
昨天要反编译一个EXE,用RESTORATOR来查看资源罗列情况,倒霉的事情发生了,所有EXE文件点右键后‘打开’都没有了,刚开始以为中度了,进安全模式看,发现文件都没有异常,并且在安全模式下问题照样 ...
- GIS专业分析方法(待更新)
遗传算法 核密度估计 http://blog.163.com/zhuandi_h/blog/static/1802702882012111092743556/ http://blog.csdn.net ...
- [洛谷P1792][国家集训队]种树
题目大意:给出由$n$个数组成的环,取某个数就可以得到它的分数,相邻的两个数不能同时取.问取$m$个数可以得到的最大分数. 题解:建一个大根堆,贪心取,每个点记录前驱后继,取一个点就把前驱后继设成不能 ...
- 整数拆分 [dp+多项式插值]
题意 $1 \leq n \leq 10^{18}$ $2 \leq m \leq 10^{18}$ $1 \leq k \leq 20$ 思路 n,m较小 首先考虑朴素的$k=1$问题: $f[i] ...
- [bzoj] 3343 教主的魔法 || 带修改分块
原题 长度为n的序列,有两种操作: 1.[l,r]区间每个数+w 2.询问[l,r]区间有多少个数>c 记录lazy数组即可. #include<cstdio> #include&l ...