标签:
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 18759 Accepted Submission(s): 9414
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<string> #include<algorithm> using namespace std; #define N 100010 #define INF 0x7ffffff #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 int tt,sum[N<<2],col[N<<2]; void pushup(int rt) { sum[rt]=sum[rt<<1]+sum[rt<<1|1]; } void build(int l,int r,int rt) { sum[rt]=1; col[rt]=0; if(l==r) { return ; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt); } void pushdown(int rt,int m) { if(col[rt]) { col[rt<<1]=col[rt<<1|1]=col[rt]; sum[rt<<1]=(m-(m>>1))*col[rt]; sum[rt<<1|1]=(m>>1)*col[rt]; col[rt]=0; } } void update(int L,int R,int c,int l,int r,int rt) { if(L<=l&&r<=R) { col[rt]=c; sum[rt]=(r-l+1)*c; return ; } pushdown(rt,r-l+1); int m=(l+r)>>1; if(L<=m) update(L,R,c,lson); if(m<R) update(L,R,c,rson); pushup(rt); } int query(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R) { return sum[rt]; } int m=(l+r)>>1,ret=0; if(L<=m) ret+=query(L,R,lson); if(m<R) ret+=query(L,R,rson); return ret; } int main() { int n,m,x,y,z,cas=1; scanf("%d",&tt); while(tt--) { scanf("%d",&n); build(1,n,1); scanf("%d",&m); while(m--) { scanf("%d%d%d",&x,&y,&z); update(x,y,z,1,n,1); } printf("Case %d: The total value of the hook is %d.\n",cas,sum[1]); cas++; } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4254565.html