标签:scanf style for include ret namespace struct void present
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 31096 Accepted Submission(s): 15313
/* 题意: n的数初始值为铜(1),然后把x到y之内的所有值都更新为z, 求最后的总值! (线段树的区间更新,外加延迟标记) */ #include <algorithm> #include <iostream> #include <cmath> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; const LL N = 100000; int n, a, b, z; typedef struct Node { int l, r, sum; int lazy, tag; } Tr; Tr x[5 * N]; /* 创建线段树 */ void creat(int d, int l, int r) { x[d].l = l; x[d].r = r; x[d].lazy = x[d].tag = 0; if(l == r) { x[d].sum = 1; return ; } int m = (l + r) / 2; creat(2 * d, l, m); creat(2 * d + 1, m + 1, r); x[d].sum = x[2 * d].sum + x[2 * d + 1].sum; } /* 区间更新模块 */ void update(int d, int l, int r, int v) { if(x[d].l == l && x[d].r == r) { x[d].lazy = 1; x[d].tag = v; x[d].sum = (r - l + 1) * v; return; } int m = (x[d].l + x[d].r) / 2; if(x[d].lazy == 1) { x[d].lazy = 0; update(d * 2, x[d].l, m, x[d].tag); update(d * 2 + 1, m + 1, x[d].r, x[d].tag); x[d].tag = 0; } if(r <= m) update(d * 2, l, r, v); else if(l > m) update(d * 2 + 1, l, r, v); else { update(d * 2, l, m, v); update(d * 2 + 1, m + 1, r, v); } x[d].sum = x[d * 2].sum + x[2 * d + 1].sum; } int main() { int m, T; while(~scanf("%d", &T)) { for(int it = 1; it <= T; it++) { scanf("%d%d", &n, &m); creat(1, 1, n); while(m--) { scanf("%d%d%d", &a, &b, &z); update(1, a, b, z); } printf("Case %d: The total value of the hook is %d.\n", it, x[1].sum); } } return 0; }
HDU 1698 Just a Hook (区间更新+延迟标记)
标签:scanf style for include ret namespace struct void present
原文地址:http://www.cnblogs.com/yu0111/p/6710954.html