题意:a数组初始全为0,b数组题目给你,有两种操作:

思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那么找出所有为0的给他的最终结果加上一并且重置为bi,维护一个区间和,询问时线段树求和。一开始updateMin没加判断,单个复杂度飙到nlog(n),疯狂TLE...

代码:

#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
const int maxn = 100000+5;
const int maxm = 100000+5;
const int MOD = 1e7;
const int INF = 0x3f3f3f3f;
using namespace std;
int n,q;
ll Min[maxn<<2],lazy[maxn<<2],sum[maxn << 2],b[maxn];
void push_down(int rt){
if(lazy[rt]){
Min[rt << 1] -= lazy[rt];
Min[rt << 1 | 1] -= lazy[rt];
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
lazy[rt] = 0;
}
}
void push_up(int rt){
Min[rt] = min(Min[rt << 1],Min[rt << 1 | 1]);
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void build(int l,int r,int rt){
if(l == r){
lazy[rt] = sum[rt] = 0;
Min[rt] = b[l];
return;
}
int m = (l + r) >> 1;
build(l,m,rt << 1);
build(m + 1,r,rt << 1 | 1);
lazy[rt] = 0;
push_up(rt);
}
void updateMin(int l,int r,int rt){
if(l == r){
if(Min[rt] == 0){
Min[rt] = b[l];
sum[rt]++;
}
return;
}
push_down(rt);
int m = (l + r) >> 1;
if(!Min[rt << 1])
updateMin(l,m,rt << 1);
if(!Min[rt << 1 | 1])
updateMin(m + 1,r,rt << 1 | 1);
push_up(rt);
}
void update(int L,int R,int l,int r,int rt){
if(L <= l && R >= r){
Min[rt]--;
lazy[rt]++;
while(!Min[rt]){
updateMin(l,r,rt);
}
return;
}
push_down(rt);
int m = (l + r) >> 1;
if(L <= m)
update(L,R,l,m,rt << 1);
if(R > m)
update(L,R,m + 1,r,rt << 1 | 1);
push_up(rt);
}
ll query(int L,int R,int l,int r,int rt){
if(L <= l && R >= r){
return sum[rt];
}
//push_down(rt);
ll ans = 0;
int m = (l + r) >> 1;
if(L <= m)
ans += query(L,R,l,m,rt << 1);
if(R > m)
ans += query(L,R,m + 1,r,rt << 1 | 1);
return ans;
}
int main(){
while(~scanf("%d%d",&n,&q)){
for(int i = 1;i <= n;i++)
scanf("%lld",&b[i]);
build(1,n,1);
char s[20];
int l,r;
while(q--){
scanf("%s%d%d",s,&l,&r);
if(s[0] == 'a'){
update(l,r,1,n,1);
}
else{
ll ans = query(l,r,1,n,1);
printf("%lld\n",ans);
}
}
}
return 0;
}
/*
5 12
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
*/

HDU 6315 Naive Operations(线段树+区间维护)多校题解的更多相关文章

  1. HDU 6315 Naive Operations(线段树区间整除区间)

    Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...

  2. 杭电多校第二场 hdu 6315 Naive Operations 线段树变形

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  3. HDU-DuoXiao第二场hdu 6315 Naive Operations 线段树

    hdu 6315 题意:对于一个数列a,初始为0,每个a[ i ]对应一个b[i],只有在这个数字上加了b[i]次后,a[i]才会+1. 有q次操作,一种是个区间加1,一种是查询a的区间和. 思路:线 ...

  4. 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, ...

  5. HDU 6315 Naive Operations(线段树+复杂度均摊)

    发现每次区间加只能加1,最多全局加\(n\)次,这样的话,最后的答案是调和级数为\(nlogn\),我们每当答案加1的时候就单点加,最多加\(nlogn\)次,复杂度可以得当保证. 然后问题就是怎么判 ...

  6. HDU - 6315(2018 Multi-University Training Contest 2) Naive Operations (线段树区间操作)

    http://acm.hdu.edu.cn/showproblem.php?pid=6315 题意 a数组初始全为0,b数组为1-n的一个排列.q次操作,一种操作add给a[l...r]加1,另一种操 ...

  7. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  8. hdu Naive Operations 线段树

    题目大意 题目链接Naive Operations 题目大意: 区间加1(在a数组中) 区间求ai/bi的和 ai初值全部为0,bi给出,且为n的排列,多组数据(<=5),n,q<=1e5 ...

  9. HDU 6315.Naive Operations-线段树(两棵树合并)(区间单点更新、区间最值、区间求和)+思维 (2018 Multi-University Training Contest 2 1007)

    6315.Naive Operations 题意很好理解,但是因为区间求和求的是向下取整的a[i]/b[i],所以直接分数更新区间是不对的,所以反过来直接当a[i]==b[i]的时候,线段树对应的位置 ...

  10. HDU 4902 Nice boat --线段树(区间更新)

    题意:给一个数字序列,第一类操作是将[l,r]内的数全赋为x ,第二类操作是将[l,r]中大于x的数赋为该数与x的gcd,若干操作后输出整个序列. 解法: 本题线段树要维护的最重要的东西就是一个区间内 ...

随机推荐

  1. JS-随机div颜色

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. MyBatis——Mapper XML 文件

    Mapper XML 文件 MyBatis 的真正强大在于它的映射语句,也是它的魔力所在.由于它的异常强大,映射器的 XML 文件就显得相对简单.如果拿它跟具有相同功能的 JDBC 代码进行对比,你会 ...

  3. parseInt()解析整数与parsetFloat()解析浮点数

    1.parseInt(string,radix) 解析整数 parseInt("dgei23"); // NaN parseInt("3 blind mice" ...

  4. 【BZOJ2809】[Apio2012]dispatching 可并堆

    [BZOJ2809][Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 M ...

  5. android通过数组,流播放声音的方法,音频实时传输

    AudioRecord和AudioTrack类是Android获取和播放音频流的重要类,放置在android.media包中.与该包中 的MediaRecorder和MediaPlayer类不同,Au ...

  6. 170808、生成为CVS文件

    /** * Desc : 生成为CVS文件 * User : RICK * @param data 源数据List * @param map csv文件的列表头map * @param outPutP ...

  7. 170724、springboot编程之完整demo

    综合之前学习,参考网上各大神博客,写了一个小demo,需要的朋友可以参考一下! 项目地址:https://github.com/zrbfree/spring-boot-anna.git

  8. Vue2.0 新手完全填坑攻略——从环境搭建到发布

    Jinkey原创感谢 showonne.yubang 技术指导Demo 地址:http://demo.jinkey.io/vue2源码:https://github.com/Jinkeycode/vu ...

  9. poj1463 Strategic game【树形DP】

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 9582   Accepted: 4516 De ...

  10. HDU_2888_Check Corners

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...