题目大意:

给定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. 1005 -- I Think I Need a Houseboat

    I Think I Need a Houseboat Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 105186   Acc ...

  2. fastjson转换包含date类型属性的对象时报错com.alibaba.fastjson.JSONException: For input string: "13:02:19"

    问题:time类型数据插入不进mysql数据库:调试的时候报如下错误: Caused by: java.lang.NumberFormatException: For input string: &q ...

  3. Shell 脚本的编码规范

  4. php 学习一 变量的定义

    //php有如下几种数据类型 // false true boolean类型 //integer int 整数 //float 浮点数就是小数 //string 字符串 //string null 空 ...

  5. PyCharm Change Font Size

    file->settings->colors&fonts-> save as (save the current scheme as your own)-> font- ...

  6. Vue开发复用组件的基本思想

    可复用组件的价值在于高复用性,它更能将一个项目往高内聚.低耦合的方向发展. 1.组件命名------按组件功能命名: 2.组件内容------明确组件需要实现什么样的功能: 3.组件体积------越 ...

  7. CSS格式化---属性排序

    一.背景 与同事合作开发一个项目,后面修改 CSS 时,发现属性顺序跟我写的不一样 我从事开发前端时,导师是有给我大概指定了一定的书写规范 现在开发时,看到的 CSS 属性排序不一样,看起来有点难受( ...

  8. 基于VMWare配置VxWorks开发环境

    常规VxWorks的开发环境都是基于目标开发板或目标机来构建的,但并非所有人都具备这样的条件,所以本文主要介绍如何基于vmware来构建VxWorks开发环境.   Step 1. 安装vmware ...

  9. 18、webservice使用

    1.将axis2.war文件拷到tomcat,webapp文件夹下,然后重启tomcat 访问

  10. 树莓派自动播报温湿度到QQ空间、微博

    原文链接 https://aoaoao.me/951.html 这是个比较无聊的应用...灵感来自于一个叫做“古城钟楼”的微博账号,此账号每天都会定点报时,除此之外没有其他任何内容,以此吸引了近50万 ...