题目大意:

给定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. 2059-authentication plugin 'caching_sha2_password"cnnot bt loaded :mysql8.0数据库连接不上(Navicat)

    原因:8.0改变了 身份验证插件 , 打开 my.ini (或者my.cofg) 可以看到变更了 5.7及其以前的方式:mysql_native_password 办法: 1:命令行键入数据库: my ...

  2. pytest---参数化

    import pytest @pytest.mark.parametrize('test_input,expected',[('3+5',8), ('2-1',1),('7*5',30)])def t ...

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

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

  4. 停止node进程

    运行vue-cli项目的时候经常出现端口号占用,npm run dev报错的信息, 此时可通过任务管理器粗暴的杀死node进程,也可以通过cmd检测占用某个端口的程序,进而杀死该进程,步骤如下: 1. ...

  5. NDK笔记(二)-在Android Studio中使用ndk-build(转)

    前面一篇我们接触了CMake,这一篇写写关于ndk-build的使用过程.刚刚用到,想到哪儿写哪儿. 环境背景 Android开发IDE版本:AndroidStudio 2.2以上版本(目前已经升级到 ...

  6. java笔试手写算法面试题大全含答案

    1.统计一篇英文文章单词个数.public class WordCounting {public static void main(String[] args) {try(FileReader fr ...

  7. 解决Zookeeper报错:conf is not executed because it is not in the whitelist的解决办法

    1.echo wchp | nc localhost 2181 ,通过路径列出服务器 watch 的详细信息,且它会输出一个与 session 相关的路径.但是出现下面的错误. [root@xg61 ...

  8. rest framework之限流组件

    一.自定义限流 限流组件又叫做频率组件,用于控制客户端可以对API进行的请求频率,比如说1分钟访问3次,如果在1分钟内超过3次就对客户端进行限制. 1.自定义限流 假设现在对一个API访问,在30s内 ...

  9. redis常用命令建议

    1. Redis查看当前所有的key KEYS * 2. 查看当前redis的配置信息 CONFIG GET * 3. MISCONF Redis is configured to save RDB ...

  10. Android中的Handler,Looper,Message机制

    Android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个Message Queue(消息队列),但是MQ被封装到Looper里面了,我们不会直接与MQ打交道,因 ...