1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std;
const int N = 2e5+10;
int T; int n, q; int A[N*4], siz[N*4], B[N*4];
void change(int k1) { A[k1] = A[k1*2] + A[k1*2+1]; } void buildtree(int k1, int l, int r) { siz[k1] = r-l+1; if(l == r) { A[k1] = 1; return; } int mid = l+r >> 1; buildtree(k1*2, l, mid); buildtree(k1*2+1, mid+1, r); change(k1); }
void update(int k1, int val) { B[k1] = val; A[k1] = val*siz[k1]; }
void pushdown(int k1) { if(B[k1]) { update(k1*2, B[k1]); update(k1*2+1, B[k1]); B[k1] = 0; } } void update(int k1, int L, int R, int l, int r, int val) { if(L > r || R < l) return; if(L >= l && R <= r) { update(k1, val); return; } int mid = L+R >> 1; pushdown(k1); update(k1*2, L, mid, l, r, val); update(k1*2+1, mid+1, R, l, r, val); change(k1); }
int Find(int k1, int L, int R, int l, int r) { if(L > r || R < l) return 0; if(L >= l && R <= r) return A[k1]; int mid = L+R >> 1; pushdown(k1); return Find(k1*2, L, mid, l, r) + Find(k1*2+1, mid+1, R, l, r);
}
int main() { scanf("%d", &T); int tt = 0; while(T--) { memset(B, 0, sizeof(B)); memset(A, 0, sizeof(A)); memset(siz, 0, sizeof(siz)); tt++; scanf("%d%d", &n, &q); buildtree(1, 1, n); int x, y, z; for(int i = 1; i <= q; i++) { scanf("%d%d%d", &x, &y, &z); update(1, 1, n, x, y, z); } printf("Case %d: The total value of the hook is %d.\n", tt, Find(1, 1, n, 1, n)); }
return 0; }
|