标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 23229 Accepted Submission(s): 11634
#include<cstdio> #include<iostream> using namespace std; #define lson l, m, cur<<1 #define rson m+1, r, cur<<1|1 const int maxn = 100005; int col[maxn<<2]; int sum[maxn<<2]; void PushUp(int cur) { sum[cur] = sum[cur<<1] + sum[cur<<1|1]; } void PushDown(int cur, int m) { if(col[cur]) { col[cur<<1] = col[cur<<1|1] = col[cur]; sum[cur<<1] = (m-(m>>1))*col[cur]; sum[cur<<1|1] = (m>>1)*col[cur]; col[cur] = 0; } } void Build(int l, int r, int cur) { col[cur] = 0; sum[cur] = 1; if(l==r) return; int m = (r+l)>>1; Build(lson); Build(rson); PushUp(cur); } void Update(int L, int R, int c, int l, int r, int cur) { if(L<=l&&r<=R) { col[cur] = c; sum[cur] = c*(r-l+1); return; } PushDown(cur, r-l+1); int m = (l+r)>>1; if(L<=m) Update(L, R, c, lson); if(R>m) Update(L, R, c, rson); PushUp(cur); } int main() { int T, n, m; scanf("%d", &T); for(int kase=1; kase<=T; kase++) { scanf("%d%d", &n, &m); Build(1, n, 1); while(m--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); Update(a, b, c, 1, n, 1); } printf("Case %d: The total value of the hook is %d.\n", kase, sum[1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4762536.html