#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 100005
typedef long long ll;
ll sum[maxn<<];
ll lazy[maxn<<];
inline void pushup(int rt){
sum[rt]=sum[rt<<]+sum[rt<<|];
}
inline void pushdown(int rt,int m){
if(lazy[rt]){
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
sum[rt<<]+=(m-(m>>))*lazy[rt];
sum[rt<<|]+=(m>>)*lazy[rt];
lazy[rt]=;
}
}
void build(int l,int r,int rt){
lazy[rt]=;
if(l==r){
scanf("%lld",&sum[rt]);
return;
}
int m=l+r>>;
build(lson);
build(rson);
pushup(rt);
}
void update(int L,int R,int val,int l,int r,int rt){
if(L<=l && R>=r){
lazy[rt]+=val;
sum[rt]+=(r-l+)*val;
return;
}
pushdown(rt,r-l+);
int m=l+r>>;
if(L<=m) update(L,R,val,lson);
if (R>m) update(L,R,val,rson);
pushup(rt);
}
ll 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=l+r>>;
ll ret=;
if(L<=m) ret+=query(L,R,lson);
if(R>m) ret+=query(L,R,rson);
return ret;
}
int main(){
int n,q,a,b,c;
while(scanf("%d%d",&n,&q)==){
build(,n,);
char op[];
while(q--){
scanf("%s",op);
if(op[]=='Q'){
scanf("%d%d",&a,&b);
printf("%lld\n",query(a,b,,n,));
}
else {
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,,n,);
}
}
}
return ;
}

poj3468的更多相关文章

  1. 【poj3468】 A Simple Problem with Integers

    http://poj.org/problem?id=3468 (题目链接) 题意 给出一个序列,要求维护区间修改与区间求和操作. Solution 多年以前学习的树状数组区间修改又忘记了→_→. 其实 ...

  2. poj3468,poj2528

    其实这两题都是基础的线段树,但对于我这个线段树的初学者来说,总结一下还是很有用的: poj3468显然是线段树区间求和,区间更改的问题,而poj2528是对区间染色,问有多少种颜色的问题: 线段树的建 ...

  3. poj3468 线段树的懒惰标记

    题目链接:poj3468 题意:给定一段数组,有两种操作,一种是给某段区间加c,另一种是查询一段区间的和 思路:暴力的方法是每次都给这段区间的点加c,查询也遍历一遍区间,复杂度是n*n,肯定过不去,另 ...

  4. poj3468 A Simple Problem with Integers(线段树区间更新)

    https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...

  5. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  6. POJ3468 A Simple Problem with Integers —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...

  7. 洛谷P3372/poj3468(线段树lazy_tag)(询问区间和,支持区间修改)

    洛谷P3372 //线段树 询问区间和,支持区间修改 #include <cstdio> using namespace std; struct treetype { int l,r; l ...

  8. POJ-3468(线段树+区间更新+区间查询)

    A Simple Problem With Integers POJ-3468 这题是区间更新的模板题,也只是区间更新和区间查询和的简单使用. 代码中需要注意的点我都已经标注出来了,容易搞混的就是up ...

  9. poj3468 A Simple Problem with Integers(zkw区间修改模板)

    此题是一道线段树的裸题,这里只是为了保存我的zkw线段树模板 #include <cstdio> #include <cstring> #include <iostrea ...

  10. [POJ3468] A Simple Problem with Integers (Treap)

    题目链接:http://poj.org/problem?id=3468 这题是线段树的题,拿来学习treap. 不旋转的treap. #include <cstdio> #include ...

随机推荐

  1. 数据分析工具urule

    Python统计学书籍 https://item.taobao.com/item.htm?spm=a1z10.1-c-s.w4004-13911786811.22.6431353b4F5iw1& ...

  2. 修改Linux Operating System的时间与时区

    修改Linux Operating System的时间与时区 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 有的小伙伴可能会遇到安装了linux系统后,尽管时区选择正确,也会发现系 ...

  3. Tomcat部署实战

    Tomcat部署实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.登录官网下载tomcat软件包(http://tomcat.apache.org/) 1>.在安装to ...

  4. 关于C#的一些小知识

    问题一 :是否可以从一个static方法内部发出对非static方法的调用? 不行,可以这样理解static修饰的方法可以直接用类名调用非static修饰的方法必须用类new出对象才能调用当我们用类名 ...

  5. 收到offer!

    今天收到了自己中意的offer,公司在上海,这也意味着自己毕业后的第一份工作也要结束了. 要说再见了,杭州,尽管相处的时间不久,也认识了一些朋友.还得向他们做声道别. 心情滋味难名,短短的一年,自己由 ...

  6. 1、Python-HelloWorld

    安装 环境下载 https://www.python.org/downloads/ IDE(PyCharm)下载 https://www.jetbrains.com/pycharm/download/ ...

  7. idea创建多模块springboot项目

    需求:一个父模块  下面几个子模块  其中一个模块是springboot结构.其他两个普通jar类型 有许多坑,都在注释里面写着呢.注意看父模块和demo模块的注释. com.imooc.securi ...

  8. Html-Css 从入门到放弃(一)基础知识

    注意要点: 1.ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用. 2.class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,clas ...

  9. 如何使用less(变量,混合,匹配,运算,嵌套...)

    如何使用less及一些常用的(变量,混合,匹配,运算,嵌套...) less的介绍及编译工具 什么是less 1.LESSCSS是一种动态样式语言,属于CSS预处理语言的一种,它使用类似CSS的语法, ...

  10. C# List分页

    假设你每页10条数据当前是第3页 跳到第4页则:List.Skip((4-1)*10).Take(10) 本文来自SunShine,转载请标明出处: http://do.jhost.cn/sunshi ...