poj3468
#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的更多相关文章
- 【poj3468】 A Simple Problem with Integers
http://poj.org/problem?id=3468 (题目链接) 题意 给出一个序列,要求维护区间修改与区间求和操作. Solution 多年以前学习的树状数组区间修改又忘记了→_→. 其实 ...
- poj3468,poj2528
其实这两题都是基础的线段树,但对于我这个线段树的初学者来说,总结一下还是很有用的: poj3468显然是线段树区间求和,区间更改的问题,而poj2528是对区间染色,问有多少种颜色的问题: 线段树的建 ...
- poj3468 线段树的懒惰标记
题目链接:poj3468 题意:给定一段数组,有两种操作,一种是给某段区间加c,另一种是查询一段区间的和 思路:暴力的方法是每次都给这段区间的点加c,查询也遍历一遍区间,复杂度是n*n,肯定过不去,另 ...
- poj3468 A Simple Problem with Integers(线段树区间更新)
https://vjudge.net/problem/POJ-3468 线段树区间更新(lazy数组)模板题 #include<iostream> #include<cstdio&g ...
- 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和
poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...
- POJ3468 A Simple Problem with Integers —— 线段树 区间修改
题目链接:https://vjudge.net/problem/POJ-3468 You have N integers, A1, A2, ... , AN. You need to deal wit ...
- 洛谷P3372/poj3468(线段树lazy_tag)(询问区间和,支持区间修改)
洛谷P3372 //线段树 询问区间和,支持区间修改 #include <cstdio> using namespace std; struct treetype { int l,r; l ...
- POJ-3468(线段树+区间更新+区间查询)
A Simple Problem With Integers POJ-3468 这题是区间更新的模板题,也只是区间更新和区间查询和的简单使用. 代码中需要注意的点我都已经标注出来了,容易搞混的就是up ...
- poj3468 A Simple Problem with Integers(zkw区间修改模板)
此题是一道线段树的裸题,这里只是为了保存我的zkw线段树模板 #include <cstdio> #include <cstring> #include <iostrea ...
- [POJ3468] A Simple Problem with Integers (Treap)
题目链接:http://poj.org/problem?id=3468 这题是线段树的题,拿来学习treap. 不旋转的treap. #include <cstdio> #include ...
随机推荐
- javascript 迭代与递归
<script type="text/javascript"> // //原生js // window.onload = function(){ // var btn ...
- JAVA中初始化ArrayList的三种方式
下面讲一下ArrayList初始化的几种不同方式. 一.最常用的初始化方式. List<String> list1 = new ArrayList<String>(); lis ...
- Study 4 —— 表单标签
表单:用于采集浏览者的相关数据.表单标记<form></form>表单的基本语法格式如下: <form action="url" method=&qu ...
- Linux 命令详解(八)Systemd 入门教程:实战篇
Systemd 入门教程:实战篇 http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
- 转 -- pydoc用法
原文地址: https://www.cnblogs.com/meitian/p/6704488.html pydoc用法 pydoc是python自带的一个文档生成工具,使用pydoc可以很方便的查看 ...
- 打包pyinstaller
安装:pip3 install pyinstaller 了解几个常用命令 参数 用处 -F 将程序打包成一个文件 -w 去除黑框 -i 添加程序图标 我们将需要打包的test.py文件放到桌面上,之后 ...
- [CQOI2011]放棋子 (DP,数论)
[CQOI2011]放棋子 \(solution:\) 看到这道题我们首先就应该想到有可能是DP和数论,因为题目已经很有特性了(首先题面是放棋子)(然后这一题方案数很多要取模)(而且这一题的数据范围很 ...
- Android五种数据存储方式
android 五种数据存储 :SharePreferences.SQLite.Contert Provider.File.网络存储 Android系统提供了四种存储数据方式.分别为:SharePre ...
- linux查看操作系统的版本
内核信息 uname -a localhost.localdomain:所在主机的主机名,与主机配置文件/etc/hosts内容一致 2.4.20-8#1:内核版本号 Thu Mar 13 17:18 ...
- Python 对图片进行人脸识别
import cv2 def detect(path): img = cv2.imread(path) cascade = cv2.CascadeClassifier("/vagrant/d ...