标签:wan integer test dota search turn memset 技术分享 src
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34697 Accepted Submission(s): 16938
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int T,n,m,tot; struct nond{ int l,r; int sum,falg; }tree[101000*4]; void up(int now){ tree[now].sum=tree[now<<1].sum+tree[now<<1|1].sum; } void build(int now,int l,int r){ tree[now].l=l; tree[now].r=r; if(tree[now].l==tree[now].r){ tree[now].sum=1; return ; } int mid=(tree[now].l+tree[now].r)>>1; build(now<<1,l,mid); build(now<<1|1,mid+1,r); up(now); } void down(int now){ tree[now<<1].sum=(tree[now<<1].r-tree[now<<1].l+1)*tree[now].falg; tree[now<<1|1].sum=(tree[now<<1|1].r-tree[now<<1|1].l+1)*tree[now].falg; tree[now<<1].falg=tree[now<<1|1].falg=tree[now].falg; tree[now].falg=0; } void change(int now,int l,int r,int x){ if(tree[now].l==l&&tree[now].r==r){ tree[now].sum=(tree[now].r-tree[now].l+1)*x; tree[now].falg=x; return; } if(tree[now].falg) down(now); int mid=(tree[now].l+tree[now].r)>>1; if(r<=mid) change(now<<1,l,r,x); else if(l>mid) change(now<<1|1,l,r,x); else{ change(now<<1,l,mid,x); change(now<<1|1,mid+1,r,x); } up(now); } int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n);tot++; memset(tree,0,sizeof(tree)); build(1,1,n); scanf("%d",&m); for(int i=1;i<=m;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); change(1,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",tot,tree[1].sum); } }
标签:wan integer test dota search turn memset 技术分享 src
原文地址:http://www.cnblogs.com/cangT-Tlan/p/7397849.html