poj 3468A Simple Problem with Integers(成段更新)
来源:互联网 发布:哪个软件可以升级win10 编辑:程序博客网 时间:2024/06/06 20:35
题目链接:http://poj.org/problem?id=3468
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;#define maxn 100010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define inf 0x3f3f3f3fLL sum[maxn<<2];LL col[maxn<<2];void PushUp(int rt){ sum[rt] = sum[rt<<1] + sum[rt<<1|1];}void PushDown(int rt,int len){ if(col[rt]){ sum[rt<<1] += col[rt] * (len - (len>>1)); sum[rt<<1|1] += col[rt] * (len>>1); col[rt<<1|1] += col[rt]; col[rt<<1] += col[rt]; col[rt] = 0; }}void build(int l,int r,int rt){ if(l == r){ scanf("%I64d",&sum[rt]); col[rt] = 0; return ; } int m = (l + r) /2; 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){ col[rt] += val; sum[rt] += (LL)(r - l + 1) * val; return ; } PushDown(rt , (r - l + 1)); int m = (l + r) /2; if(L <= m) update(L,R,val,lson); if(m < R) 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 + 1); int m = (l + r)/2; LL ret = 0; if(L <= m) ret += query(L,R,lson); if(m < R) ret += query(L,R,rson); return ret;}int main(){ int n,m,a,b,c; char op[5]; while(~scanf("%d %d",&n,&m)){ build(1,n,1); while(m--){ scanf("%s",op); if(op[0] == 'C'){ scanf("%d %d %d",&a,&b,&c); if(a>b) swap(a,b); update(a,b,c,1,n,1); } else{ scanf("%d %d",&a,&b); if(a>b) swap(a,b); printf("%I64d\n",query(a,b,1,n,1)); } } } return 0;}
- POJ 3468 A Simple Problem with Integers 成段更新
- poj 3468A Simple Problem with Integers(成段更新)
- POJ 3468 A Simple Problem with Integers 成段更新,总区间求和
- POJ 3468 A Simple Problem with Integers(成段更新)
- poj 3468 A Simple Problem with Integers(线段树|成段更新,区间查询)
- 线段树 POJ 3468 A Simple Problem with Integers 线段树 成段更新入门
- POJ 3468 A Simple Problem with Integers 线段树 成段更新
- 区间树 [成段更新] POJ 3468 A Simple Problem with Integers
- poj 3468 A Simple Problem with Integers(线段树,成段更新)
- 线段树模板(二)——成段更新 + POJ 3468 A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers 线段树 (成段更新)
- [ACM] poj 3468 A Simple Problem with Integers(线段树,成段更新,懒惰标记)
- POJ 3468 A Simple Problem with Integers //线段树的成段更新
- 线段树(成段更新) 之 poj 3468 A Simple Problem with Integers
- POJ 3468 A Simple Problem with Integers(成段更新)
- poj 3468 A Simple Problem with Integers (线段树---成段更新)
- Poj 3468 A Simple Problem with Integers 成段更新,区间求和
- POJ 3468-A Simple Problem with Integers(线段树:成段更新,区间求和)
- javascript中事件解析
- 英文字体的应用
- 我的第一个Cocos2d-x程序
- 嵌入式环境下的算法开发之学习建议
- CCAnimation创建动画 cocos2d-x
- poj 3468A Simple Problem with Integers(成段更新)
- ActiveMQ入门教程(六) - ActiveMQ与Spring整合-MessageListener
- matlab获取向量中出现次数最多的元素
- 约瑟夫环问题 (c / c++)
- 0-1 背包算法实现[java版有瑕疵,你可以看看]
- 导入其它css文件
- poj 2528 Mayor's posters (区间更新)
- 运行和控制Nginx
- 数据结构与算法目录