QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#713162#7992. 【模板】线段树szy10010TL 0ms12088kbC++202.5kb2024-11-05 18:22:152024-11-05 18:22:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 18:22:16]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:12088kb
  • [2024-11-05 18:22:15]
  • 提交

answer

#include<iostream>
#include<set>
#include<queue>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<unordered_map>

#define pb push_back
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(),(x).end()
#define _for(i, a) for(int i = 0; i < (a); ++i) 
#define _rep(i, a, b) for(int i = (a);i <= (b); ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define u1 (u<<1)
#define u2 (u<<1|1)
//#define endl '\n'
using namespace std;
typedef pair<int,int> PII;

const int N =4e5+10;
const long long mod=(1<<20);
#define int long long 
int n,lzy[N],tot,a[N],pos[N],q,U[640][640],T[640][640],Ex[640][640],l[N],r[N];
inline int read(){
	char c; c=getchar(); int sum=0;
	while(c<'0'||c>'9')	c=getchar();
	while(c>='0'&&c<='9')	sum=sum*10+(c-'0'),c=getchar();
	return sum;
}
void CG(int x){
	for(int i=1;i<=20;i++)	T[x][i]=0; 
	T[x][0]=1;
	for(int i=l[x];i<=r[x];i++)	
		for(int j=20;j>=0;j--){
			if(j!=0)	T[x][j]=((T[x][j]%mod*a[i]%mod)%mod+T[x][j-1])%mod;
			else	T[x][j]=(T[x][j]%mod*a[i]%mod)%mod;
		}
}
void Devide(){
	int len=sqrt(n),tot=n/len; if(len*len!=n)	tot++;
	for(int i=1;i<=tot;i++)	l[i]=(i-1)*len+1,r[i]=l[i]+len-1;
	r[tot]=n;
	for(int i=1;i<=tot;i++)	for(int j=l[i];j<=r[i];j++)	pos[j]=i;
	for(int i=1;i<=tot;i++)	CG(i);
}
void update(int L,int R,int x){
	if(pos[L]==pos[R]){
		for(int i=L;i<=R;i++)	a[i]+=x,a[i]%=mod;
		CG(pos[L]);
		return ;
	}
	for(int i=L;i<=r[pos[L]];i++)	a[i]+=x,a[i]%=mod; CG(pos[L]);
	for(int i=l[pos[R]];i<=R;i++)	a[i]+=x,a[i]%=mod; CG(pos[R]);
	for(int i=pos[L]+1;i<=pos[R]-1;i++)	lzy[i]+=x,lzy[i]%=mod;
}
int Query(int L,int R){
	int ans=1;
	if(pos[L]==pos[R]){
		for(int i=L;i<=R;i++)	ans*=(a[i]+lzy[pos[L]])%mod,ans%=mod;
		return ans;
	}
	for(int i=L;i<=r[pos[L]];i++)	ans*=(a[i]+lzy[pos[L]])%mod,ans%=mod;
	for(int i=l[pos[R]];i<=R;i++)	ans*=(a[i]+lzy[pos[R]])%mod,ans%=mod;
	for(int i=pos[L]+1;i<=pos[R]-1;i++){
		int Sum=0,prs=20;
		int lst=min(prs,r[i]-l[i]+1);
		for(int j=1,p=0;p<=lst;p++,j=(j%mod*lzy[i]%mod)%mod)	Sum+=T[i][p]*j,Sum%=mod; // i block p jieduan 
		ans=ans*Sum; ans%=mod;	
	}
	return ans;
}
void solve(){
	n=read(),q=read();
	for(int i=1;i<=n;i++)	a[i]=read();
	Devide();
	while(q--){
		int op,l,r,x;
		op=read(),l=read(),r=read();
		if(op==1)	x=read(),update(l,r,x);
		else printf("%lld\n",Query(l,r));
	}
}
signed main(){

	int T=1;
//	cin>>T;
	_rep(i,1,T){
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 12088kb

input:

10 10
969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323
1 5 6 3034
2 1 10
2 1 9
2 1 4
1 3 6 126904
2 5 5
2 9 9
1 7 7 853094
1 4 9 1025178
2 5 8

output:

1045541
1012343
558151
580413
810659
527353

result:

ok 6 lines

Test #2:

score: -100
Time Limit Exceeded

input:

200000 200000
496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...

output:

746709
564663
426791
840425
762201
413693
881143
534387
189149
257625
60619
958793
250635
869079
383765
151047
272239
146175
46215
914259
617511
698623
381177
932779
792705
785375
1044293
202971
508317
237901
634919
646839
38501
304017
889609
214899
617927
720071
628729
202369
420511
528565
555717
7...

result: