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): 0 Accepted Submission(s): 0
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
1
2
4
4
6
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int inf = 0x3f3f3f3f;
const int M = 1e5+;
double lazy[M<<];
double b[M],num[M],sum[M<<],minn[M<<];
vector<int>v;
void pushup(int rt){
minn[rt] = min(minn[rt<<],minn[rt<<|]);
} void pushdown(int rt){
if(lazy[rt]){
lazy[rt<<] += lazy[rt];
lazy[rt<<|] += lazy[rt];
minn[rt<<] -= lazy[rt];
minn[rt<<|] -= lazy[rt];
lazy[rt] = ;
}
} void build(int l,int r,int rt){
lazy[rt] = ; minn[rt] = inf;
if(l == r){
minn[rt] = b[l];
return ;
}
mid;
build(lson);
build(rson);
pushup(rt);
} void update(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
minn[rt] -= ;
lazy[rt] += ;
return ;
}
pushdown(rt);
mid;
if(L <= m) update(L,R,lson);
if(R > m) update(L,R,rson);
pushup(rt);
} void update2(int p,int l,int r,int rt){
if(l == r){
minn[rt] = b[l];
return ;
}
mid;
pushdown(rt);
if(p <= m) update2(p,lson);
else update2(p,rson);
pushup(rt);
} int Query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return minn[rt];
}
mid;
pushdown(rt);
int ret = inf;
if(L <= m) ret = min(Query(L,R,lson),ret);
if(R > m) ret = min(Query(L,R,rson),ret);
return ret;
} void query1(int l,int r,int rt){
if(l == r){
v.push_back(l);
return ;
}
mid;
pushdown(rt);
pushdown(rt);
if(minn[rt<<] == ) query1(lson);
if(minn[rt<<|] == ) query1(rson);
} void pushup1(int rt){
sum[rt] = sum[rt<<] + sum[rt<<|];
} void build1(int l,int r,int rt){
sum[rt] = ;
if(l == r){
sum[rt] = ;
return ;
}
mid;
build1(lson);
build1(rson);
pushup1(rt);
} void update1(int p,int l,int r,int rt){
if(l == r){
sum[rt] += ;
return ;
}
mid;
if(p <= m) update1(p,lson);
else update1(p,rson);
pushup1(rt);
} int query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return sum[rt];
}
mid;
int ret = ;
if(L <= m) ret += query(L,R,lson);
if(R > m) ret += query(L,R,rson);
return ret;
} int main()
{
int n,q,x,l,r;
char op[];
while(scanf("%d%d",&n,&q)!=EOF){
for(int i = ;i <= n;i ++){
scanf("%d",&x);
b[i] = x;
}
build(,n,);
build1(,n,);
while(q--){
scanf("%s",op);
if(op[] == 'a'){
//cout<<"update"<<endl;
scanf("%d%d",&l,&r);
update(l,r,,n,); //将第一棵树的l,r区间-1
int cnt = Query(l,r,,n,);//求第一棵树的l,r区间的最小值
//cout<<"cnt: "<<cnt<<endl;
if(cnt == ){ //如果区间最小值为0
query1(,n,); //找到区间所有0的下表寸进vector里
for(int i = ;i < v.size(); i++){ //遍历
//cout<<"v[i] :"<<v[i]<<endl;
update1(v[i],,n,); //在第二颗数记下更新值
update2(v[i],,n,); //将现在为0的数变成原来的值
}
v.clear();
}
}
else {
//cout<<"query"<<endl;
scanf("%d%d",&l,&r);
int ans = query(l,r,,n,);
printf("%d\n",ans);
}
}
}
return ;
}
hdu 6315 Naive Operations (2018 Multi-University Training Contest 2 1007)的更多相关文章
- HDU 6315 Naive Operations(线段树+区间维护)多校题解
题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...
- HDU 6351 Naive Operations(线段树)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6315 Naive Operations Time Limit: 6000/3000 MS (Java/O ...
- 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 线段树变形
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
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- 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 【势能线段树】
<题目链接> 题目大意: 给出两个序列,a序列全部初始化为0,b序列为输入值.然后有两种操作,add x y就是把a数组[x,y]区间内全部+1,query x y是查询[x,y]区间内∑ ...
- HDU 6315 Naive Operations(线段树+复杂度均摊)
发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...
随机推荐
- 微信小程序开发 [02] 页面注册和基本组件
1.页面注册 既然我们希望跳转到新的页面,那自然要新建页面相关的文件才行.在开篇已经讲过,一个小程序页面由四个文件组成,假如我们的页面名为welcome,那么这四个文件则是: welcome.js w ...
- 第7章 使用寄存器点亮LED灯
第7章 使用寄存器点亮LED灯 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fir ...
- 网络对抗技术 2017-2018-2 20152515 Exp5 MSF基础应用
1.实践内容(3.5分) 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路. 1.1一个主动攻击实践,如ms08_067; (1分) MS08-067漏洞攻击 这次使用 ...
- 20155306白皎 《网络对抗》 Exp9 Web安全基础实践
20155306白皎 <网络对抗> Exp9 Web安全基础实践 一.基本问题回答 SQL注入攻击原理,如何防御 原理是: 就是通过把SQL命令插入到"Web表单递交" ...
- 20155308《信息安全系统设计基础 嵌入式C语言课堂考试补博客
20155308<信息安全系统设计基础 嵌入式C语言课堂考试补博客 知识点 置位 ?bits = bits | (1 << 7) ; /* sets bit 7 */ bits |= ...
- WPF编程,通过Double Animation动态旋转控件的一种方法。
原文:WPF编程,通过Double Animation动态旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...
- WPF自定义控件的自定义属性绑定后不更新问题
原文:WPF自定义控件的自定义属性绑定后不更新问题 需要在绑定时设置属性变更触发 UpdateSourceTrigger=PropertyChanged 例如: <Border CornerRa ...
- pandas 初识(一)
基本内容 Series: Series 是有一组数据(numpy的数据类型 numpy.ndarray)以及一组数据标签(即索引)组成,可以看成一个一个定长的有序字典(索引值到数据值的一个映射) ob ...
- opencv core组件进阶
1.图像在内存中存储方式,图像矩阵的大小取决于颜色模型,取决于所有的通道数:还有重要的颜色空间缩减的概念:因为如果是RGB的话,使用uchar的话,就有256^3的结合方法.所以要用到颜色缩减的方法, ...
- 上云利器,K8S应用编排设计器之快到极致
前言在前面的文章中,我们已经提到,华为云有一个上云利器:应用编排设计器.作为华为云应用编排服务与用户沟通的桥梁,设计器坚持用户体验至上的理念,以图形化方式,在鼠标点击之间,助力企业快速上云.优质的交互 ...