题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6315

题目大意:告诉你a,b两个数组,a数组初始化为0,b数组告诉你长度和具体值,接下来有q次操作,add操作是从向区间[l,r]加1,query操作是求区[l,r]的ai/bi的总和。

解题思路:维护一个mn,表示这个区间里的a最少加几次才能有新的贡献。比如1最多对总和造成q的贡献,2最多q/2,q/3,q/4,一直到q/n。最少要加min(b[i]-a[i]%b[i])次才能有新的贡献,如果这个区间+1之后没有贡献,也就是mn>1,就直接打标记.

AC代码:

 #include<iostream>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define lson rt<<1
#define rson rt<<1|1
#define Lson l,m,lson
#define Rson m+1,r,rson
typedef long long ll; const ll mod= 1e9+;
const int maxn=1e5+; int n;
int a[maxn],b[maxn];
char s[]; int lazy[maxn<<],sum[maxn<<],mn[maxn<<];
void pushup(int rt){
sum[rt]=sum[lson]+sum[rson];
mn[rt]=min(mn[lson],mn[rson]);
}
void pushdown(int rt,int m){
if(lazy[rt]==){
return;
}
lazy[lson]+=lazy[rt];
lazy[rson]+=lazy[rt];
mn[lson]-=lazy[rt];
mn[rson]-=lazy[rt];
lazy[rt]=;
} void build(int l,int r,int rt){
lazy[rt]=;
sum[rt]=;
if(l==r){
mn[rt]=b[l];
return ;
}
int m=(l+r)>>;
build(Lson);
build(Rson);
pushup(rt);
} void update(int L,int R,int add,int l,int r,int rt){
if(L<=l&&r<=R&&mn[rt]>){
lazy[rt]++,mn[rt]--;
return ;
}
if(l==r){
sum[rt]++;
mn[rt]=b[l];
return ;
}
pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m) update(L,R,add,Lson);
if(m<R) update(L,R,add,Rson);
pushup(rt);
} int query(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R){
return sum[rt];
}
pushdown(rt,r-l+);
int m=(r+l)>>,ret=;
if(L<=m) ret+=query(L,R,Lson);
if(m<R) ret+=query(L,R,Rson);
return ret;
}
int main(){
int q;
while(~scanf("%d%d",&n,&q)){
for(int i=;i<=n;i++){
scanf("%d",&b[i]);
}
build(,n,);
while(q--){
int l,r;
scanf("%s %d %d",s,&l,&r);
if(s[]=='a'){
update(l,r,,,n,);
}else{
printf("%d\n",query(l,r,,n,));
}
}
}
return ;
}

(2018 Multi-University Training Contest 2)Problem G - Naive Operations的更多相关文章

  1. (2018 Multi-University Training Contest 3)Problem D. Euler Function

    //题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 //题目大意:给定 k,求第 k 小的数 n,满足 φ(n) 是合数.显然 φ(1) = 1 ...

  2. (2018 Multi-University Training Contest 3)Problem L. Visual Cube

      //题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6330//题目大意:按照一定格式画出一个 a×b×c 的长方体.  #include <b ...

  3. ( 2018 Multi-University Training Contest 2)

    2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...

  4. zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)

    题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...

  5. HDU 5726 GCD (2016 Multi-University Training Contest 1)

      Time Limit: 5000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Give y ...

  6. HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

    Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. HDU 4897 Little Devil I(树链剖分)(2014 Multi-University Training Contest 4)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4897 Problem Description There is an old country and ...

  8. HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)

    题意:构造出n个数 这n个数取值范围0-L,这n个数中存在取一些数之和等于k,则这样称为一种方法.给定n,k,L,求方案数. 思路:装压 每位 第1为表示这种方案能不能构成1(1表示能0表示不能)   ...

  9. hdu6315( 2018 Multi-University Training Contest 2)

    bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6315 /*hdu 1007 首先我们在建立线段树之前应该思考的是线段树的节点维护一个什么 ...

随机推荐

  1. SpringMVC成员变量并发状态下使用测试

    1.SpringMVC默认是单例的,使用成员变量在并发状态下该成员变量的值是被共享的 测试平台 我们目前正在开发的电商项目  (架构组成SpringCloud + SpringBoot + Sprin ...

  2. GC知识记录

    2.关于Minor GC,Major GC与Full GC 1)  Minor GC:即新生代的GC,指发生在新生代的垃圾收集动作.当新生代的Eden区内存不足时,就会触发Minor GC.由于对象创 ...

  3. Windows下安装Anaconda

    Windows下安装Anaconda   Anaconda介绍 Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项.因为包含了大量的科学 ...

  4. Android之人脸识别

    **前言** 人工智能时代快速来临,其中人脸识别是当前比较热门的技术,在国内也越来越多的运用,例如刷脸打卡.刷脸App,身份识别,人脸门禁等等.当前的人脸识别技术分为WEBAPI和SDK调用两种法方式 ...

  5. git命令合并分支代码

    对于复杂的系统,我们可能要开好几个分支来开发,那么怎样使用git合并分支呢? 合并步骤:1.进入要合并的分支(如开发分支合并到master,则进入master目录)git checkout maste ...

  6. pycharm上传代码到远程服务器

    本来不打算写了,可是,还是记不住 源自https://blog.csdn.net/zhangyu4863/article/details/80188207 我的是pycharm2018.1.4专业版: ...

  7. Cocos Creator学习三:生命周期回调函数

    1.目的:学习生命周期回调函数以及回调顺序,更有利于我们逻辑的处理把控. 2.生命周期回调函数: 节点:指cc.Node:组件:指cc.Component. ①onLoad:脚本组件绑定的节点所在场景 ...

  8. font-spider-plus,字体压缩插件使用笔记

    font-spider-plus使用笔记, fsp是一个腾讯的大佬改版后的font-soider 主要思路是 采集线上网页使用到的字体,从字体文件中分离出来,完成大幅度压缩, 1,npm i font ...

  9. 文献导读 | Single-Cell Sequencing of iPSC-Dopamine Neurons Reconstructs Disease Progression and Identifies HDAC4 as a Regulator of Parkinson Cell Phenotypes

    文献编号:19Mar - 11 2019年04月23日三读,会其精髓: 相信这种方法的话,那么它的精髓是什么,如何整合出这个core gene set. 首先要考虑样本的选择,样本里是否存在明显的分层 ...

  10. Confluence 6 针对合并完全失败的内容重新运行合并

    如果在系统合并的时候有任何内容的合并失败的话,一个 Confluence 的管理员可以再次重新启动内容合并(请参考前面页面的内容).只有内容还是使用 wiki 格式的才会被合并,因此重新合并所需要的时 ...