ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184729 | #584. t3 | wosile | 100 | 3995ms | 39076kb | C++ | 2.7kb | 2023-09-12 11:28:37 | 2023-09-12 12:07:33 |
answer
#include<bits/stdc++.h>
using namespace std;
int c[15][15];
int sum[400005][15];
const int mod=1000000007;
int a[100005][15],lz1[4000005],lz2[4000005];
int d[15];
void pushup(int x){
for(int i=0;i<=10;i++)sum[x][i]=(sum[x<<1][i]+sum[x<<1|1][i])%mod;
}
void build(int l,int r,int x){
if(l==r){
for(int i=0;i<=10;i++)sum[x][i]=a[l][i];
return;
}
int mid=(l+r)/2;
build(l,mid,x<<1);
build(mid+1,r,x<<1|1);
pushup(x);
}
void pushdown(int x){
if(lz2[x]<0x3f3f3f3f){
int v=lz2[x];
for(int i=1;i<=10;i++)sum[x<<1][i]=1LL*sum[x<<1][i-1]*v%mod,sum[x<<1|1][i]=1LL*sum[x<<1|1][i-1]*v%mod;
lz2[x<<1]=lz2[x<<1|1]=lz2[x];
lz1[x<<1]=lz1[x<<1|1]=0;
}
else if(lz1[x]!=0){
int v=lz1[x];
d[0]=1;
for(int i=1;i<=10;i++)d[i]=1LL*d[i-1]*v%mod;
for(int i=10;i>=0;i--)for(int j=0;j<i;j++)sum[x<<1][i]=(sum[x<<1][i]+1LL*sum[x<<1][j]*c[i][j]%mod*d[i-j])%mod,sum[x<<1|1][i]=(sum[x<<1|1][i]+1LL*sum[x<<1|1][j]*c[i][j]%mod*d[i-j])%mod;;
if(lz2[x<<1]==0x3f3f3f3f)lz1[x<<1]=(lz1[x<<1]+v)%mod;
else lz2[x<<1]=(lz2[x<<1]+v)%mod;
if(lz2[x<<1|1]==0x3f3f3f3f)lz1[x<<1|1]=(lz1[x<<1|1]+v)%mod;
else lz2[x<<1|1]=(lz2[x<<1|1]+v)%mod;
}
lz1[x]=0;
lz2[x]=0x3f3f3f3f;
}
void update(int l,int r,int x,int L,int R,int op,int v){
if(L<=l && r<=R){
if(op==1){
d[0]=1;
for(int i=1;i<=10;i++)d[i]=1LL*d[i-1]*v%mod;
for(int i=10;i>=0;i--)for(int j=0;j<i;j++)sum[x][i]=(sum[x][i]+1LL*sum[x][j]*c[i][j]%mod*d[i-j])%mod;
if(lz2[x]==0x3f3f3f3f)lz1[x]=(lz1[x]+v)%mod;
else lz2[x]=(lz2[x]+v)%mod;
}
else{
for(int i=1;i<=10;i++)sum[x][i]=1LL*sum[x][i-1]*v%mod;
lz2[x]=v;
lz1[x]=0;
}
return;
}
int mid=(l+r)/2;
pushdown(x);
if(L<=mid)update(l,mid,x<<1,L,R,op,v);
if(R>mid)update(mid+1,r,x<<1|1,L,R,op,v);
pushup(x);
}
int query(int l,int r,int x,int L,int R,int v){
if(L<=l && r<=R)return sum[x][v];
int mid=(l+r)/2;
int ans=0;
pushdown(x);
if(L<=mid)ans=(ans+query(l,mid,x<<1,L,R,v))%mod;
if(R>mid)ans=(ans+query(mid+1,r,x<<1|1,L,R,v))%mod;
pushup(x);
return ans;
}
int main(){
// freopen("t3.in","r",stdin);
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i][1]);
for(int i=1;i<=n;i++){
a[i][0]=1;
for(int j=2;j<=10;j++)a[i][j]=1LL*a[i][j-1]*a[i][1]%mod;
}
for(int i=0;i<=10;i++){
c[i][0]=1;
for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
memset(lz2,0x3f,sizeof(lz2));
build(1,n,1);
for(int i=1;i<=m;i++){
int op,l,r,x;
scanf("%d%d%d%d",&op,&l,&r,&x);
if(op<=2)update(1,n,1,l,r,op,x);
else printf("%d\n",query(1,n,1,l,r,x));
}
return 0;
}
/*
5 12
1 1 2 4 6
1 1 5 2
3 1 5 0
3 1 5 1
3 1 5 2
3 1 5 3
3 1 5 4
3 1 5 5
3 1 5 6
3 1 5 7
3 1 5 8
3 1 5 9
3 1 5 10
*/
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 16924kb
input:
458 823 14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...
output:
806084096 117884357 581509507 903754571 381316325 789203673 312340523 659242359 741787988 89040104 4...
result:
ok 261 lines
Test #2:
score: 10
Accepted
time: 5ms
memory: 16928kb
input:
481 526 8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...
output:
867105097 717265913 288311190 320452351 133 498037408 473281413 216488030 182572597 611630662 471106...
result:
ok 179 lines
Test #3:
score: 10
Accepted
time: 596ms
memory: 39072kb
input:
100000 100000 15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...
output:
54433 544457741 352487648 82525935 532381851 235929450 38218 30045720 19138 459644406 33559 30953524...
result:
ok 33327 lines
Test #4:
score: 10
Accepted
time: 582ms
memory: 39072kb
input:
100000 100000 6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...
output:
18923 13111195 41716 34447 32091 80654 731180277 9973 523560023 19797 159789457 695071461 3136 95363...
result:
ok 33328 lines
Test #5:
score: 10
Accepted
time: 601ms
memory: 39076kb
input:
100000 100000 15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...
output:
754347097 6296 588341566 325967942 180064833 683 831351544 63953 57030 17635 175222109 5280 57193 32...
result:
ok 33349 lines
Test #6:
score: 10
Accepted
time: 588ms
memory: 39072kb
input:
100000 100000 14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...
output:
17008 73008 935797904 16519312 15383 25232 236856418 75334 25854 46510 797344028 517157465 595936107...
result:
ok 33304 lines
Test #7:
score: 10
Accepted
time: 258ms
memory: 27960kb
input:
50000 50000 17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...
output:
19498 473297203 695948777 299749756 50630760 692747746 369627246 181903142 328502296 939823794 69850...
result:
ok 16802 lines
Test #8:
score: 10
Accepted
time: 249ms
memory: 27796kb
input:
50000 50000 10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...
output:
717018991 140916081 273712387 602991268 878512570 665908548 10388 4939 283493752 435656498 657720400...
result:
ok 16814 lines
Test #9:
score: 10
Accepted
time: 514ms
memory: 38492kb
input:
90000 90000 29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...
output:
738835738 738703020 3888 402391875 37270 872563699 273399892 807398793 365897262 255303782 93280847 ...
result:
ok 29904 lines
Test #10:
score: 10
Accepted
time: 602ms
memory: 39072kb
input:
100000 100000 23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...
output:
576735050 562509678 553431297 662173102 515338212 478400370 879269281 500659410 483381164 1679282 16...
result:
ok 33309 lines