标签:sizeof ret otto 技术分享 bsp contain most follow algorithm
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 30901 Accepted Submission(s):
15221
Problem Description
不过写完才发现这个直接输出val[1]就好了
贴代码
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int t=0,n=0,val[400010],mark[400010],m=0,x=0,y=0,z=0; 7 8 void build(int pos,int ll,int rr){ 9 if(ll==rr){ 10 val[pos]=1; 11 mark[pos]=0; 12 return; 13 } 14 else{ 15 int mid=(ll+rr)/2; 16 build(2*pos,ll,mid); 17 build(2*pos+1,mid+1,rr); 18 val[pos]=val[2*pos]+val[2*pos+1]; 19 } 20 } 21 22 void down(int pos,int num){ 23 if(mark[pos]){ 24 val[2*pos]=mark[pos]*(num-num/2); 25 val[2*pos+1]=mark[pos]*(num/2);//attention! 26 mark[2*pos]=mark[2*pos+1]=mark[pos]; 27 mark[pos]=0; 28 } 29 } 30 31 void change(int pos,int ll,int rr){ 32 if(x>rr||y<ll) return; 33 if(x<=ll&&y>=rr){ 34 val[pos]=z*(rr-ll+1); 35 mark[pos]=z; 36 return; 37 } 38 down(pos,rr-ll+1); 39 int mid=(ll+rr)/2; 40 change(2*pos,ll,mid); 41 change(2*pos+1,mid+1,rr); 42 val[pos]=val[2*pos]+val[2*pos+1]; 43 } 44 45 int main(){ 46 scanf("%d",&t); 47 for(int i=1;i<=t;i++){ 48 memset(val,0,sizeof(val)); 49 memset(mark,0,sizeof(mark)); 50 scanf("%d",&n); 51 build(1,1,n); 52 scanf("%d",&m); 53 for(int j=1;j<=m;j++){ 54 scanf("%d%d%d",&x,&y,&z); 55 change(1,1,n); 56 } 57 printf("Case %d: The total value of the hook is %d.\n",i,val[1]); 58 } 59 return 0; 60 }
又长又臭又慢的线段树 模板题hdu1698 Just a Hook
标签:sizeof ret otto 技术分享 bsp contain most follow algorithm
原文地址:http://www.cnblogs.com/sdfzxh/p/6669578.html