标签:sub hide c++ 区间 help led his 更新 line
Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others)
Total Submission(s): 9392 Accepted Submission(s): 2408
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define debug(x) cout<<"["<<#x<<"]"<<" is "<<x<<endl 4 #define forp(x) for(int i=1;i<=x;i++) 5 #define scai(x) scanf("%d",&x) 6 #define scal(x) scanf("%lld",&x) 7 #define pri(x) printf("%d\n",x) 8 #define prl(x) printf("%lld\n",x) 9 typedef long long ll; 10 const int maxn=1e5+5; 11 const ll mod=1e4+7; 12 struct node{ 13 int l; 14 int r; 15 ll ad; 16 ll mu; 17 ll a[4]; 18 }N[maxn<<2]; 19 void pushup(int rt){ 20 N[rt].a[1]=N[rt<<1].a[1]+N[(rt<<1)|1].a[1]; 21 N[rt].a[2]=N[rt<<1].a[2]+N[(rt<<1)|1].a[2]; 22 N[rt].a[3]=N[rt<<1].a[3]+N[(rt<<1)|1].a[3]; 23 N[rt].mu%=mod; 24 N[rt].ad%=mod; 25 N[rt].a[1]%=mod; 26 N[rt].a[2]%=mod; 27 N[rt].a[3]%=mod; 28 } 29 void pushdown(int rt){ 30 if(N[rt].mu!=1){ 31 ll m=N[rt].mu; 32 N[rt].mu=1; 33 N[rt<<1].ad=N[rt<<1].ad*m%mod; 34 N[(rt<<1)|1].ad=N[(rt<<1)|1].ad*m%mod; 35 N[rt<<1].mu=N[rt<<1].mu*m%mod; 36 N[(rt<<1)|1].mu=N[(rt<<1)|1].mu*m%mod; 37 N[rt<<1].a[1]=N[rt<<1].a[1]*m%mod; 38 N[rt<<1].a[2]=N[rt<<1].a[2]*m%mod*m%mod; 39 N[rt<<1].a[3]=N[rt<<1].a[3]*m%mod*m%mod*m%mod; 40 N[(rt<<1)|1].a[1]=N[(rt<<1)|1].a[1]*m%mod; 41 N[(rt<<1)|1].a[2]=N[(rt<<1)|1].a[2]*m%mod*m%mod; 42 N[(rt<<1)|1].a[3]=N[(rt<<1)|1].a[3]*m%mod*m%mod*m%mod; 43 } 44 if(N[rt].ad!=0){ 45 ll m=N[rt].ad; 46 N[rt].ad=0; 47 N[rt<<1].ad=N[rt<<1].ad+m%mod; 48 N[(rt<<1)|1].ad=N[(rt<<1)|1].ad+m%mod; 49 N[rt<<1].a[3]=N[rt<<1].a[3]+m%mod*m%mod*m%mod*(N[rt<<1].r-N[rt<<1].l+1)%mod+3*m*N[rt<<1].a[2]%mod+3*m%mod*m%mod*N[rt<<1].a[1]%mod; 50 N[rt<<1].a[3]%=mod; 51 N[rt<<1].a[2]=N[rt<<1].a[2]+m%mod*m%mod*(N[rt<<1].r-N[rt<<1].l+1)%mod+2*m*N[rt<<1].a[1]%mod; 52 N[rt<<1].a[2]%=mod; 53 N[rt<<1].a[1]=N[rt<<1].a[1]+m*(N[rt<<1].r-N[rt<<1].l+1)%mod; 54 N[rt<<1].a[1]%=mod; 55 N[(rt<<1)|1].a[3]=N[(rt<<1)|1].a[3]%mod+m%mod*m%mod*m%mod*(N[(rt<<1)|1].r-N[(rt<<1)|1].l+1)%mod+3*m*N[(rt<<1)|1].a[2]%mod+3*m%mod*m%mod*N[(rt<<1)|1].a[1]%mod; 56 N[(rt<<1)|1].a[3]%=mod; 57 N[(rt<<1)|1].a[2]=N[(rt<<1)|1].a[2]%mod+m%mod*m%mod*(N[(rt<<1)|1].r-N[(rt<<1)|1].l+1)%mod+2*m*N[(rt<<1)|1].a[1]%mod; 58 N[(rt<<1)|1].a[2]%=mod; 59 N[(rt<<1)|1].a[1]=N[(rt<<1)|1].a[1]+m*(N[(rt<<1)|1].r-N[(rt<<1)|1].l+1)%mod; 60 N[(rt<<1)|1].a[1]%=mod; 61 } 62 } 63 void build(int L,int R,int rt){ 64 N[rt].l=L; 65 N[rt].r=R; 66 N[rt].mu=1; 67 N[rt].ad=0; 68 if(L==R){ 69 N[rt].a[1]=0; 70 N[rt].a[2]=0; 71 N[rt].a[3]=0; 72 return; 73 } 74 int mid=(L+R)/2; 75 build(L,mid,rt<<1); 76 build(mid+1,R,(rt<<1)|1); 77 pushup(rt); 78 } 79 void update(int L,int R,int rt,int l1,int r1,ll add,ll mul){ 80 N[rt].mu%=mod; 81 N[rt].ad%=mod; 82 N[rt].a[1]%=mod; 83 N[rt].a[2]%=mod; 84 N[rt].a[3]%=mod; 85 if(l1<=L&&r1>=R){ 86 if(mul!=1){ 87 ll m=mul; 88 N[rt].ad=N[rt].ad*m%mod; 89 N[rt].mu=N[rt].mu*m%mod; 90 N[rt].a[1]=N[rt].a[1]*m%mod; 91 N[rt].a[2]=N[rt].a[2]*m%mod*m%mod; 92 N[rt].a[3]=N[rt].a[3]*m%mod*m%mod*m%mod; 93 } 94 if(add!=0){ 95 ll m=add; 96 N[rt].ad=N[rt].ad+m%mod; 97 N[rt].a[3]=N[rt].a[3]+m%mod*m%mod*m%mod*(N[rt].r-N[rt].l+1)%mod+3*m*N[rt].a[2]%mod+3*m%mod*m%mod*N[rt].a[1]%mod; 98 N[rt].a[3]%=mod; 99 N[rt].a[2]=N[rt].a[2]+m%mod*m%mod*(N[rt].r-N[rt].l+1)%mod+2*m%mod*N[rt].a[1]%mod; 100 N[rt].a[2]%=mod; 101 N[rt].a[1]=N[rt].a[1]+m*(N[rt].r-N[rt].l+1)%mod; 102 N[rt].a[1]%=mod; 103 } 104 return; 105 } 106 pushdown(rt); 107 int mid=(L+R)/2; 108 if(mid>=l1){ 109 update(L,mid,rt<<1,l1,r1,add,mul); 110 } 111 if(mid<r1){ 112 update(mid+1,R,(rt<<1)|1,l1,r1,add,mul); 113 } 114 pushup(rt); 115 } 116 ll query(int L,int R,int rt,int l1,int r1,int p){ 117 N[rt].mu%=mod; 118 N[rt].ad%=mod; 119 N[rt].a[1]%=mod; 120 N[rt].a[2]%=mod; 121 N[rt].a[3]%=mod; 122 if(l1<=L&&r1>=R){ 123 return N[rt].a[p]%mod; 124 } 125 int mid=(L+R)/2; 126 ll ak=0; 127 pushdown(rt); 128 if(mid>=l1){ 129 ak+=query(L,mid,rt<<1,l1,r1,p); 130 } 131 if(mid<r1){ 132 ak+=query(mid+1,R,(rt<<1)|1,l1,r1,p); 133 } 134 135 136 return ak%mod; 137 } 138 int main(){ 139 int n,m; 140 scai(n); 141 scai(m); 142 while(n||m){ 143 build(1,n,1); 144 forp(m){ 145 ll a,b,c,d; 146 scal(a); 147 scal(b); 148 scal(c); 149 scal(d); 150 if(a==1){ 151 update(1,n,1,b,c,d,1); 152 } 153 else if(a==2){ 154 update(1,n,1,b,c,0,d); 155 } 156 else if(a==3){ 157 update(1,n,1,b,c,d,0); 158 } 159 else{ 160 prl(query(1,n,1,b,c,d)); 161 } 162 } 163 scai(n); 164 scai(m); 165 } 166 return 0; 167 }
标签:sub hide c++ 区间 help led his 更新 line
原文地址:https://www.cnblogs.com/MekakuCityActor/p/10804864.html