题目大意:

给定n q 为序列的个数和操作的个数

给定n个数的序列b[]作为分母

初始全为0的序列a[]作为分子

两种操作

add l r 为a[]的l到r区间全部+1

query l r 为查询l到r区间a[i]/b[i]的总和(向下取整)

因为是向下取整 所以线段树维护区间的min(b[i]-a[i]%b[i])

那么当区间的这个最小的sub值为0时 说明这个区间内至少有一个点有新的贡献

所以当sub值为0时 才更新答案并向下更新 否则更新lazy和sub即可

即在代码中 更新lazy和sub 当sub恰好等于0 那么更新now

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
#define mem(i,j) memset(i,j,sizeof(i))
using namespace std;
const int N=1e5+;
const int MOD=1e9+;
int n, m, b[N]; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
LL lazy[N<<], now[N<<], sub[N<<];
void pushUp(int rt) {
sub[rt]=min(sub[rt<<],sub[rt<<|]);
now[rt]=now[rt<<]+now[rt<<|];
}
void pushDown(int rt) {
if(lazy[rt]) {
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
sub[rt<<]-=lazy[rt];
sub[rt<<|]-=lazy[rt];
lazy[rt]=;
}
}
void build(int l,int r,int rt) {
lazy[rt]=; now[rt]=;
if(l==r) {
sub[rt]=b[l];
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushUp(rt);
}
void updatesub(int l,int r,int rt) {
if(l==r) {
now[rt]++; sub[rt]=b[l];
return;
}
pushDown(rt);
int m=(l+r)>>;
if(sub[rt<<]==) updatesub(lson);
if(sub[rt<<|]==) updatesub(rson);
pushUp(rt);
}
void update(int L,int R,int l,int r,int rt) {
if(L<=l && r<=R) {
lazy[rt]++; sub[rt]--;
if(sub[rt]==) updatesub(l,r,rt);
return;
}
pushDown(rt);
int m=(l+r)>>;
if(L<=m) update(L,R,lson);
if(m<R) update(L,R,rson);
pushUp(rt);
}
int query(int L,int R,int l,int r,int rt) {
if(L<=l && r<=R) return now[rt];
pushDown(rt);
int m=(l+r)>>;
int res=;
if(L<=m) res+=query(L,R,lson);
if(m<R) res+=query(L,R,rson);
return res;
}
void init() {
mem(now,); mem(sub,); mem(lazy,);
} int main()
{
while(~scanf("%d%d",&n,&m)) {
for(int i=;i<=n;i++) scanf("%d",&b[i]);
init(); build(,n,);
while(m--) {
char op[]; scanf("%s",op);
int l,r; scanf("%d%d",&l,&r);
if(op[]=='a') update(l,r,,n,);
else printf("%d\n",query(l,r,,n,));
}
} return ;
}

hdu6315 /// 线段树区间更新的更多相关文章

  1. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  2. hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新

    #1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...

  3. HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...

  4. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  5. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  6. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  7. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  8. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  9. HDU5039--Hilarity DFS序+线段树区间更新 14年北京网络赛

    题意:n个点的树,每个条边权值为0或者1, q次操作 Q 路径边权抑或和为1的点对数, (u, v)(v, u)算2个. M i修改第i条边的权值 如果是0则变成1, 否则变成0 作法: 我们可以求出 ...

随机推荐

  1. css3 盒模型与 伪元素综合应用案例

    先来简略理解下盒模型: 在 css3 之前,盒模型默认为 box-sizing : content-box,这种模式下的盒模型计算大小方式为,width + padding + border : 而 ...

  2. VS2008的使用

    文章转载自:http://www.cnblogs.com/aduck/archive/2011/11/11/2245460.html 1.如何在vc2008中显示行号 中文版: 菜单-工具-选项 在新 ...

  3. multiple-cursors做代码对齐

    multiple-cursors做代码对齐 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839 ...

  4. mysql全局权限账户%登录不上ERROR 1045 (28000): Access denied for user 'zzq'@'localhost' (using password: YES)

    mysql中有新建了一个%(允许所有主机连接)和ALL权限的账户.但是竟然连不上.用root或者其他localhost的用户却可以登录.首先检查下防火墙打开了没,可以用service iptables ...

  5. dubbo接口未更新,清maven缓存问题

    有时候idea maven reimport 并未更新到最新的版本 此时可以到./m2去进行手动清楚缓存再更新 cd .m2/repository/cn/dface/biz/couponcenter ...

  6. a标签动态修改手机号跳到拨打界面

    <div class="primaryButton"> <a :href.stop="'tel:' + createData.salesPhone&qu ...

  7. pytest-Allure安装

    mac安装allure brew install allure---安装 brew info allure---查看信息 mac端需要配置环境变量 win安装: windows/mac通用安装 • h ...

  8. ollvm 编译

    ollvm 的编译相对 llvm 更简单, 1:下载ollvm代码,去 https://github.com/obfuscator-llvm/obfuscator/tree/llvm-4.0 下载,并 ...

  9. python之数据序列转换并同时计算数据

    问题 你需要在数据序列上执行聚集函数(比如 sum() , min() , max() ), 但是首先你需要先转换或者过滤数据 解决方案 一个非常优雅的方式去结合数据计算与转换就是使用一个生成器表达式 ...

  10. Chrome不支持css字体小于12px的解决办法

    我们先来看个效果图(chrome下): 从上面的图可以很明显地看出Chrome下css设置字体大小为12px及以下时,显示的都是一样大小,都是默认12px: 那么网上有一个方法就是给当前样式添加Chr ...