poj3468 A Simple Problem with Integers 线段树区间更新
来源:互联网 发布:在哪注册域名比较好 编辑:程序博客网 时间:2024/04/30 00:02
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>using namespace std;#define maxn 110000#define ll long long#define lson rt<<1,l,m#define rson rt<<1|1,m+1,rll tree[maxn<<2],add[maxn<<2];void pushup(int rt){ tree[rt]=tree[rt<<1]+tree[rt<<1|1];}void pushdown(int num,int mid){ if(add[num]) { add[num<<1] += add[num]; add[num<<1|1] += add[num]; tree[num<<1] += ((mid-(mid>>1)) * add[num]); tree[num<<1|1] += ((mid>>1) * add[num]); add[num] = 0; }}void build(int rt,int l,int r){ add[rt]=0; if(l==r) { scanf("%lld",&tree[rt]); return; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt);}void update(int rt,int l,int r,int x,int y,int val){ if(x<=l&&y>=r) { add[rt]+=val; tree[rt] += (ll)val * (r - l + 1); return; } pushdown(rt,r-l+1); int m=(l+r)>>1; if(x<=m) { update(lson,x,y,val); } if(y>m) { update(rson,x,y,val); } pushup(rt);}ll query(int rt,int l,int r,int x,int y){ if(x==l&&y==r) { return tree[rt]; } pushdown(rt,r-l+1); int m=(l+r)>>1; ll tmp=0; if(x>m) { return query(rson,x,y); } else if(y<=m) { return query(lson,x,y); } else { return query(lson,x,m)+query(rson,m+1,y); }}int main(){ int n,m,q; char str[5]; scanf("%d%d",&n,&m); build(1,1,n); for(int i=1;i<=m;i++) { //printf("op = %d %d\n",op,n); int a,b,c; scanf("%s",str); if(str[0]=='Q') { scanf("%d%d",&a,&b); printf("%lld\n",query(1,1,n,a,b)); } else if(str[0]=='C') { scanf("%d%d%d",&a,&b,&c); update(1,1,n,a,b,c); } } return 0;}
0 0
- poj3468 A Simple Problem with Integers 线段树区间更新
- Poj3468 A Simple Problem with Integers 线段树、区间更新
- 【poj3468-A Simple Problem with Integers】-线段树区间更新
- POJ3468 A Simple Problem with Integers 线段树 区间成段更新+区间求和
- 线段树 区间更新 区间查询 poj3468 A Simple Problem with Integers
- poj3468 A Simple Problem with Integers 线段树延迟标记区间更新区间求和
- poj3468 A Simple Problem with Integers 线段树区间更新,区间求和
- poj3468 A Simple Problem with Integers(线段树,区间更新,区间和查询)
- poj3468 A Simple Problem with Integers 线段树 延时更新
- poj3468 A Simple Problem with Integers 线段树 更新延迟
- 线段树 区间更新 访问POJ3468 A Simple Problem with Integers解题报告
- POJ3468 - A Simple Problem with Integers (线段树 区间更新)
- POJ3468 A Simple Problem with Integers(线段树 lazy思想 区间查询更新)
- poj3468——A Simple Problem with Integers(线段树,区间更新)
- poj3468 A Simple Problem with Integers 线段树 区间更新 lazy
- POJ3468 A Simple Problem with Integers(线段树区间更新,lazy标记)
- POJ3468 A Simple Problem with Integers (线段树区间更新)
- poj3468 A Simple Problem with Integers(线段树+区间更新+非完全替换)模板
- 最近公共祖先
- Linux设备驱动之Ioctl控制
- 完整SpringMVC上传图片组件及保存图片地址到数据库
- Android MediaPlayer类详解
- 简洁的tableview
- poj3468 A Simple Problem with Integers 线段树区间更新
- 求解!!
- 动态规划的初次接触,简单分析
- android数据存取的四种方式
- #import 与 @class的区别
- 详解Spring中的CharacterEncodingFilter
- Android 增量更新实例(Smart App Updates)
- work_weipa_viewpager
- 【易微信系列一】查找附近的人