HDU 1556 Color the ball 线段树模板题
来源:互联网 发布:平底皮鞋女款淘宝 编辑:程序博客网 时间:2024/06/04 19:31
#include <stdio.h>#define ll long long#define lson l, m, rt<<1#define rson m + 1, r, rt<<1|1#define root 1, N, 1const int maxn = 100005;ll add[maxn<<2];ll sum[maxn<<2];void pushUp(int rt){ sum[rt] = sum[rt<<1] + sum[rt<<1|1];}void pushDown(int rt, int m){ if(add[rt]){ add[rt<<1] += add[rt]; add[rt<<1|1] += add[rt]; sum[rt<<1] += add[rt] * (m - (m >> 1)); sum[rt<<1|1] += add[rt] * (m>>1); add[rt] = 0; }}void build(int l, int r, int rt){ add[rt] = 0; if(l == r){ sum[rt] = 0; return; } int m = (l + r) >> 1; build(lson); build(rson); pushUp(rt);}void update(int L, int R, int c, int l, int r, int rt){ if(L <= l&&r <= R){ add[rt] += c; sum[rt] += (ll)c * (r - l + 1); return; } pushDown(rt, r - l + 1); int m = (l + r) >> 1; if(L <= m) update(L, R, c, lson); if(m < R) update(L, R, c, 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) >>1; ll ret = 0; if(L <= m) ret += query(L, R, lson); if(m < R) ret += query(L, R, rson); return ret;}int main(){ int a, b, N; while(scanf("%d", &N) != EOF) { if(N == 0) break; build(root); for(int i = 0;i < N;i++) { scanf("%d %d", &a, &b); update(a, b, 1, root); } for(int i = 1;i <= N;i++) printf("%lld%c", query(i, i, root), i==N?'\n':' '); }}
0 0
- HDU 1556 Color the ball 线段树模板题
- HDU 1556 Color the ball 线段树
- HDU 1556 Color the ball (线段树)
- HDU 1556 Color the ball 线段树
- hdu 1556 Color the ball(线段树)
- hdu 1556 Color the ball 线段树
- HDU 1556 Color the ball 线段树
- HDU 1556 Color the ball [线段树]
- HDU 1556 Color the ball (线段树)
- hdu - 1556 (Color the ball 线段树)
- HDU 1556 Color the ball 线段树入门题
- HDU 1556 Color the ball 线段树区间更新裸模板
- HDU 1556 Color the ball(线段树区间更新区间查询模板)
- Color the ball (线段树,区间更新模板题)
- hdu 1566 Color the ball---线段树
- HDU 1199 Color the Ball (线段树)
- hdu 1556 Color the ball(线段树的另一种应用)
- hdu 1556 Color the ball(线段树+懒惰标记)
- Activiti学习笔记三-开发部署bpmn流程文件
- 欢迎使用CSDN-markdown编辑器
- C++primer学习:重载运算符(3)
- id ,NSObject, id<NSObject>区别
- 【NOIP】10.24/25 总结
- HDU 1556 Color the ball 线段树模板题
- ARM9开发板FL2440移植Linux-3.0内核————触摸屏的移植
- filddler学习
- Web应用中request获取path,URI,URL
- Popover 初探
- 编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制
- HDU - 1711 Number Sequence(KMP)
- 黑马程序员——Java 基础:权限
- 关于asp.net[没有相关的源行]错误的解决方法及IIS安装问题