fafu 1008
1 #include2 #include 3 const int N=100000+5; 4 int n, q; 5 int a[N], tree[N<<2], t[N<<2]; 6 7 void build(int rt, int l, int r) 8 { 9 if(l==r)10 tree[rt]=10;11 else12 {13 int m=(l+r)>>1;14 build(rt<<1, l, m);15 build((rt<<1)+1, m+1, r);16 17 tree[rt]=tree[rt<<1]+tree[(rt<<1)+1];18 }19 }20 21 void pushDown(int rt, int m)22 {23 if(t[rt]!=-1)24 {25 t[rt<<1]=t[rt];26 t[(rt<<1)+1]=t[rt];27 tree[rt<<1]=t[rt]*(m-(m>>1));28 tree[(rt<<1)+1]=t[rt]*(m>>1);29 t[rt]=-1;30 }31 }32 33 void update(int rt, int l, int r, int x, int y, int v)34 {35 if(x<=l && r<=y)36 {37 t[rt]=v;38 tree[rt]=(r-l+1)*v;39 return;40 }41 pushDown(rt, r-l+1);42 int m=(l+r)>>1;43 if(x<=m)44 update(rt<<1, l, m, x, y, v);45 if(m y?x:y;65 update(1, 1, n, mi, ma, v);66 }67 printf("Case %d: The total value of the stick is %d.\n", k, tree[1]);68 }69 return 0;70 }