hdu 1698 Just a Hook
来源:互联网 发布:宋佳和谢天笑 知乎 编辑:程序博客网 时间:2024/05/17 23:39
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698
线段树简单题,纯当练习一下英文。。
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#define lc root<<1#define rc root<<1|1#define mid ((l+r)>>1)const int Max_N = 100010;struct Node { int v, add; };struct SegTree { Node seg[Max_N << 2]; inline void built(int root, int l, int r) { seg[root].add = 0; if (l == r) { seg[root].v = 1; return; } built(lc, l, mid); built(rc, mid + 1, r); seg[root].v = seg[lc].v + seg[rc].v; } inline void push_down(int root, int len) { if (seg[root].add != 0) { int &x = seg[root].add; seg[lc].add = seg[rc].add = x; seg[lc].v = (len - (len >> 1)) * x; seg[rc].v = (len >> 1) * x; x = 0; } } inline void update(int root, int l, int r, int x, int y, int add) { if (x > r || y < l) return; if (x <= l && y >= r) { seg[root].add = add; seg[root].v = (r - l + 1) * add; return; } push_down(root, r - l + 1); update(lc, l, mid, x, y, add); update(rc, mid + 1, r, x, y, add); seg[root].v = seg[lc].v + seg[rc].v; } inline int query() { return seg[1].v; }}seg;int main() {#ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout);#endif int t, n, m, a, b, c, k = 1; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &m); seg.built(1, 1, n); while (m--) { scanf("%d %d %d", &a, &b, &c); seg.update(1, 1, n, a, b, c); } printf("Case %d: The total value of the hook is %d.\n", k++, seg.query()); } return 0;}
0 0
- hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- Hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- hdu 1698 just a hook
- hdu 1698 Just a Hook
- HDU 1698 Just a Hook
- hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- HDU-1698-Just a Hook
- hdu 1698 Just a Hook
- hdu 1698 Just a Hook
- HDU 1698 Just a Hook
- HDU 1698 - Just a Hook
- hdu 1698 Just a Hook
- HDU 1698 Just a Hook
- H264中的SPS、PPS提取与作用
- Maven软件项目管理工具使用
- Android内存监测工具DDMS->Heap,内存分析工具->MAT
- 什么是事件起泡,用jquery阻止事件起泡
- 黑马程序员--Java基础Day03
- hdu 1698 Just a Hook
- LA 4256 Salesmen 线性dp
- OC release之后 retainCount为何为1
- Ecliplse 重命名后web.xml 报错Attribute "xmlns" was already specified for element "web-app".
- 使用 APPLY
- Servlet,Filter,Listener,Interceptor
- JavaScript:Object.prototype.toString方法的原理
- Java连接sqlserver数据库
- 对于计算机网络课本中一个题目理解