标签:test min follow actual length using hdu1698 tin ber
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 54923 Accepted Submission(s): 25566
1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 5 const int MAXN=1e5+5; 6 int st[MAXN<<2],lazy[MAXN<<2];///lazy懒标记数组 7 8 void pushup(int rt){ 9 st[rt]=st[rt<<1]+st[rt<<1|1]; 10 } 11 12 void pushdown(int l,int r,int rt){ 13 if(lazy[rt]==0)return; 14 lazy[rt<<1]=lazy[rt]; 15 lazy[rt<<1|1]=lazy[rt]; 16 int mid=(l+r)>>1; 17 st[rt<<1]=lazy[rt]*(mid-l+1); 18 st[rt<<1|1]=lazy[rt]*(r-mid); 19 lazy[rt]=0; 20 } 21 22 void build(int l,int r,int rt){ 23 lazy[rt]=0; 24 if(l==r){ 25 st[rt]=1; 26 return; 27 } 28 int mid=(l+r)>>1; 29 pushdown(l,r,rt); 30 build(l,mid,rt<<1); 31 build(mid+1,r,rt<<1|1); 32 pushup(rt); 33 } 34 35 void update(int L,int R,int val,int l,int r,int rt){ 36 if(L<=l&&r<=R){ 37 lazy[rt]=val; 38 st[rt]=(r-l+1)*val; 39 return; 40 } 41 pushdown(l,r,rt); 42 int mid=(l+r)>>1; 43 if(L<=mid)update(L,R,val,l,mid,rt<<1); 44 if(R>mid)update(L,R,val,mid+1,r,rt<<1|1); 45 pushup(rt); 46 } 47 48 int query(int L,int R,int l,int r,int rt){ 49 if(L<=l&&r<=R)return st[rt]; 50 pushdown(l,r,rt); 51 int mid=(l+r)>>1,res=0; 52 if(L<=mid)res+=query(L,R,l,mid,rt<<1); 53 if(R>mid)res+=query(L,R,mid+1,r,rt<<1|1); 54 pushup(rt); 55 return res; 56 } 57 58 int main(){ 59 int t,n,q,x,y,z,ca=0; 60 scanf("%d",&t); 61 while(t--){ 62 scanf("%d%d",&n,&q); 63 build(1,n,1); 64 while(q--){ 65 scanf("%d%d%d",&x,&y,&z); 66 update(x,y,z,1,n,1); 67 } 68 printf("Case %d: The total value of the hook is %d.\n",++ca,st[1]); 69 } 70 }
hdu1698 Just a Hook(线段树+区间修改+区间查询+模板)
标签:test min follow actual length using hdu1698 tin ber
原文地址:https://www.cnblogs.com/ChangeG1824/p/11508236.html