UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213116#584. t3fddwd2011ms66928kbC++114.2kb2024-11-09 20:21:282024-11-09 23:14:03

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fir first
#define sec second
#define MAXN 100010
const int mod=1e9+7;
int n,m;
ll a[MAXN],C[11][11];
struct nod{
	int l,r;ll val[11],lazy=0;set<pll>lazy1;pll lazy2={0,0};
}tree[MAXN<<2];
inline ll power(ll a,ll b){
	if(!a) return 0;
	if(!b||a==1) return 1;
	if(b&1) return power(a,b-1)*a%mod;
	ll x=power(a,b>>1);return x*x%mod;
}inline void change(int id,ll delta){
	ll val[11];memset(val,0,sizeof(val));
	for(int i=0;i<=10;++i)for(int j=0;j<=i;++j)
		(val[i]+=C[i][j]*power(delta,i-j)%mod*tree[id].val[j])%=mod;
	for(int i=0;i<=10;++i) tree[id].val[i]=val[i];
}inline void pushdown(int id){
	if(tree[id].l==tree[id].r){tree[id].lazy2={0,0};return;}
	int v=id<<1;bool flag=false;
	if(tree[id].lazy2>tree[v].lazy2) tree[v].lazy2=tree[id].lazy2,flag=true;
	while(!tree[v].lazy1.empty()&&(*tree[v].lazy1.begin()).fir<tree[v].lazy2.sec)
		change(v,mod-(*tree[v].lazy1.begin()).sec),
		(tree[v].lazy+=mod-(*tree[v].lazy1.begin()).sec)%=mod,
		tree[v].lazy1.erase(tree[v].lazy1.begin());
	if(flag){
		tree[v].val[0]=tree[v].r-tree[v].l+1;
		for(int i=1;i<=10;++i)
			tree[v].val[i]=(tree[v].val[i-1]*tree[v].lazy2.sec)%mod;
		change(v,tree[v].lazy);
	}for(auto it=tree[id].lazy1.begin();it!=tree[id].lazy1.end();++it)
		if(!tree[v].lazy1.count(*it))
			tree[v].lazy1.insert(*it),change(v,(*it).sec),
			(tree[v].lazy+=(*it).sec)%=mod;
	++v,flag=false;
	if(tree[id].lazy2>tree[v].lazy2) tree[v].lazy2=tree[id].lazy2,flag=true;
	while(!tree[v].lazy1.empty()&&(*tree[v].lazy1.begin()).fir<tree[v].lazy2.sec)
		change(v,mod-(*tree[v].lazy1.begin()).sec),
		(tree[v].lazy+=mod-(*tree[v].lazy1.begin()).sec)%=mod,
		tree[v].lazy1.erase(tree[v].lazy1.begin());
	if(flag){
		tree[v].val[0]=tree[v].r-tree[v].l+1;
		for(int i=1;i<=10;++i)
			tree[v].val[i]=(tree[v].val[i-1]*tree[v].lazy2.sec)%mod;
		change(v,tree[v].lazy);
	}for(auto it=tree[id].lazy1.begin();it!=tree[id].lazy1.end();++it)
		if(!tree[v].lazy1.count(*it))
			tree[v].lazy1.insert(*it),change(v,(*it).sec),
			(tree[v].lazy+=(*it).sec)%=mod;
}inline void pushup(int id){
	if(tree[id].l==tree[id].r) return;
	pushdown(id),pushdown(id<<1),pushdown(id<<1|1);
	for(int i=0;i<=10;++i)
		tree[id].val[i]=(tree[id<<1].val[i]+tree[id<<1|1].val[i])%mod;
}inline void st_build(int id,int l,int r){
	tree[id].l=l,tree[id].r=r;
	if(l==r){
		tree[id].val[0]=1;
		for(int i=1;i<=10;++i) tree[id].val[i]=tree[id].val[i]*a[i]%mod;
		return;
	}int mid=(l+r)>>1;
	st_build(id<<1,l,mid),st_build(id<<1|1,mid+1,r),pushup(id);
}inline void st_modify1(int id,int l,int r,int s,ll delta){
	if(l<=tree[id].l&&tree[id].r<=r){
		tree[id].lazy1.insert({s,delta});
		return;
	}pushdown(id);
	int mid=(tree[id].l+tree[id].r)>>1;
	if(l<=mid) st_modify1(id<<1,l,r,s,delta);
	if(mid<r) st_modify1(id<<1|1,l,r,s,delta);
	pushup(id);
}inline void st_modify2(int id,int l,int r,int s,ll num){
	if(l<=tree[id].l&&tree[id].r<=r){
		tree[id].lazy2={s,num};
		tree[id].val[0]=tree[id].r-tree[id].l+1;
		for(int i=1;i<=10;++i) tree[id].val[i]=(tree[id].val[i-1]*num)%mod;
		return;
	}pushdown(id);
	int mid=(tree[id].l+tree[id].r)>>1;
	if(l<=mid) st_modify2(id<<1,l,r,s,num);
	if(mid<r) st_modify2(id<<1|1,l,r,s,num);
	pushup(id);
}inline ll st_query(int id,int l,int r,int p){
	pushdown(id);
	if(l<=tree[id].l&&tree[id].r<=r) return tree[id].val[p];
	int mid=(tree[id].l+tree[id].r)>>1;
	ll sum=0;
	if(l<=mid) sum+=st_query(id<<1,l,r,p);
	if(mid<r) sum+=st_query(id<<1|1,l,r,p);
	return sum;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=0;i<=10;++i) C[i][0]=1;
	for(int i=1;i<=10;++i)for(int j=1;j<=i;++j)
		C[i][j]=C[i-1][j]+C[i-1][j-1];
	st_build(1,1,n);
	short type;int l,r,x;
	for(int s=1;s<=m;++s){
		cin>>type>>l>>r>>x;
		if(n<=1000){
			if(type==1) for(int i=l;i<=r;++i) (a[i]+=x)%=mod;
			if(type==2) for(int i=l;i<=r;++i) a[i]=x;
			if(type==3){
				ll ans=0;
				for(int i=l;i<=r;++i) (ans+=power(a[i],x))%=mod;
				cout<<ans<<endl;
			}continue;
		}
		if(type==1) st_modify1(1,l,r,s,x);
		if(type==2) st_modify2(1,l,r,s,x);
		if(type==3) cout<<st_query(1,l,r,x)<<endl;
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 66928kb

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: 7ms
memory: 66924kb

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: 0
Time Limit Exceeded

input:

100000 100000
15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...

output:

54433
134340600
29055060
0
500067609
1043385546
19585
0
0
67567566
21731
706331175
10157
937387507
1...

result:


Test #4:

score: 0
Time Limit Exceeded

input:

100000 100000
6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...

output:

18923
0
26311
13811
6250
27742
2136802716
0
1005681257
2919
1674199938
2120540
0
353819535
108472896...

result:


Test #5:

score: 0
Time Limit Exceeded

input:

100000 100000
15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...

output:

664534548
0
244473380
1851287434
18213641
0
1981012094
13655
5518
1445
624252985
4141
49668
13742070...

result:


Test #6:

score: 0
Time Limit Exceeded

input:

100000 100000
14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...

output:

17008
73008
274917396
1862569739
10937
6250
5438554371
60571
24206
39598
6729466
3195477094
0
108296...

result:


Test #7:

score: 0
Time Limit Exceeded

input:

50000 50000
17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...

output:

19498
0
80699883
764947686
494173666
2470817561
900820643
814778465
1358397319
906225352
3356992156
...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

50000 50000
10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...

output:

0
56736135
987661662
925008134
0
1103859077
13
2465
1758278132
851758027
2685269967
1199308965
14055...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

90000 90000
29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...

output:

0
0
0
1852898168
10140
1293459689
30138482
1084782807
1192535518
2478953178
11572786
1071805147
1964...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

100000 100000
23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...

output:

0
0
0
0
27301151
927251943
0
952563498
1647554126
0
6984
888895806
830089903
0
1817560450
7031
11958...

result: