A Simple Problem with Integers
来源:互联网 发布:好听的淘宝达人名字 编辑:程序博客网 时间:2024/05/19 13:23
B - A Simple Problem with Integers
#include<stdio.h>#include<iostream>#define LL long longusing namespace std;struct node{long long l, r, sum, mark;}btree[100005*4];void build(LL l, LL r, LL i){btree[i].l = l;btree[i].r = r;btree[i].sum = 0;btree[i].mark = 0;if (l == r){scanf("%lld", &btree[i].sum);return;}LL mid = (l + r) / 2;build(l, mid, i * 2);build(mid + 1, r, i * 2 + 1);btree[i].sum = btree[i * 2].sum + btree[i * 2 + 1].sum;}void pushdow(int i){btree[i * 2].sum += (btree[i * 2].r - btree[i * 2].l + 1)*btree[i].mark;btree[i * 2 + 1].sum += (btree[i * 2 + 1].r - btree[i * 2 + 1].l + 1)*btree[i].mark;btree[i * 2].mark += btree[i].mark;btree[i * 2 + 1].mark += btree[i].mark;btree[i].mark = 0;}void ADD(LL l, LL r, LL x, LL i){if (l == btree[i].l&&r == btree[i].r){btree[i].sum += (btree[i].r - btree[i].l + 1)*x;btree[i].mark += x;return;}if (btree[i].mark)pushdow(i);LL mid = (btree[i].l + btree[i].r) / 2;if (r <= mid){ADD(l, r, x, i * 2);}else if (l > mid){ADD(l, r, x, i * 2 + 1);}else{ADD(l, mid, x, i * 2);ADD(mid + 1, r, x, i * 2 + 1);}btree[i].sum = btree[i * 2].sum + btree[i * 2 + 1].sum;}LL Find(int l, int r, int i){if (l == btree[i].l&&r == btree[i].r){return btree[i].sum;}if (btree[i].mark)pushdow(i);int mid = (btree[i].l + btree[i].r) / 2;if (r <= mid)return Find(l, r, i * 2);else if (l > mid){return Find(l, r, i * 2 + 1);}else return Find(l, mid, i * 2) + Find(mid + 1, r, i * 2 + 1);}int main(){LL n, m;while(cin >> n >> m){build(1, n, 1);char st[2];for (int i = 0; i < m; i++){scanf("%s", st);if (st[0] == 'C'){long long a, b, c;scanf("%lld%lld%lld", &a, &b, &c);ADD(a, b, c, 1);}else{long long a, b;scanf("%lld%lld", &a, &b);printf("%lld\n", Find(a, b, 1));}}}return 0;}
0 0
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- A Simple Problem with Integers
- 导航栏和电池栏一个颜色 + TableView在电池栏下
- E. Lost in WHU。矩阵快速幂!
- Image to Image 几何校正
- Unity3D Shader之路 写Shader前必须要知道的事情 渲染流水线的概括
- java中synchronized块是怎么用的给个例子
- A Simple Problem with Integers
- mysql索引查询
- Spring中的调度器是在spring3.0以上使用的时task注解
- Linux操作指令(3)
- CodeForces 787B Not Afraid
- 虚拟机ubuntu扩容
- java中死锁的概念是什么给个例子
- String类(****)
- POJ 2496 Apple Tree