QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403340#7782. Ursa MinorretaliatorEliteWA 1ms4056kbC++145.0kb2024-05-02 09:00:192024-05-02 09:00:20

Judging History

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

  • [2024-05-02 09:00:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4056kb
  • [2024-05-02 09:00:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline long long read(){
	long long ret=0,neg=1;
	char ch;
	ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		neg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		ret=(ret<<1)+(ret<<3)+(ch^48);
		ch=getchar();
	}
	return ret*neg;
}
void write(long long x){
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}

const long long mod=1000000007998244353,Base=7539375027;

const int Blim=200;

int n,q;
long long a[200010];
long long dif[200010];

vector<long long> BIT[3+((1+Blim)*Blim/2)];
int Bid[Blim+3][Blim+3];
int Bidx;

inline int Get_pos(int k,int pos){
	return ((pos-1)/k)+1;
}

inline void Add(int id,int pos,long long del){
	for(;pos<BIT[id].size();pos+=pos-((pos-1)&pos)){
		//cout<<pos<<endl;
		BIT[id][pos]+=del;
	}
}
inline long long Ask(int id,int pos){
	long long ret=0;
	for(;pos;pos=pos&(pos-1)){
		ret+=BIT[id][pos];
	}
	return ret;
}

inline void Min_Modify(int pos,long long del){
	//dif[pos]+=del;
	for(int i=1;i<=Blim;++i){
		Add(Bid[i][pos%i],Get_pos(i,pos),del);
	}
}

int Gcd(int x,int y){
	if(x==0) return y;
	return Gcd(y%x,x);
}

long long pw[2][200010];
long long ksm(long long x,long long t){
	long long ret=1;
	while(t){
		if(t&1){
			ret=(__int128)x*ret%mod;
		}
		x=(__int128)x*x%mod;
		t>>=1;
	}
	return ret;
}

long long bIT[200010];
inline void aDD(int pos,long long del){
	for(;pos<=n;pos+=pos-((pos-1)&pos)){
		//cout<<pos<<endl;
		bIT[pos]+=del;
		bIT[pos]=bIT[pos]>=mod?bIT[pos]-mod:bIT[pos];
	}
}
inline long long aSK(int pos){
	/*__int128 qqq=0;
	for(int i=1;i<=pos;++i){
		qqq=(qqq+(__int128)(a[i]+mod)*pw[0][n-i])%mod;
	}*/

	long long ret=0;
	for(;pos;pos=pos&(pos-1)){
		ret+=bIT[pos];
		ret=ret>=mod?ret-mod:ret;
	}
	//assert(qqq==ret);
	return ret;
}

namespace Primagen{
	int m;
	int b[200010];
	int ST[200010][20];
	int Lg[200010];
	inline void Build(){
		for(int i=0;i<=20;++i){
			for(int j=(1<<i);j<=min(m,(1<<(i+1))-1);++j)
				Lg[j]=i;
		}
		for(int i=1;i<=m;++i){
			ST[i][0]=b[i];
		}
		for(int j=1;j<=18;++j){
			for(int i=1;i+(1<<j)-1<=m;++i){
				ST[i][j]=Gcd(ST[i][j-1],ST[i+(1<<(j-1))][j-1]);
			}
		}
	}
	inline int Ask(int l,int r){
		int tmp=Lg[r-l+1];
		return Gcd(ST[l][tmp],ST[r-(1<<tmp)+1][tmp]);
	}
}

int main(){
	//freopen("circle3.in","r",stdin);
	//freopen("circle.out","w",stdout);
	n=read();
	Primagen::m=read();
	q=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		dif[i]=a[i]-a[i-1];
	}
	for(int i=1;i<=Primagen::m;++i){
		Primagen::b[i]=read();
	}
	Primagen::Build();
	//cout<<Primagen::Ask(3,4)<<endl;
	for(int i=1;i<=min(n,Blim);++i){
		int len=(n/i)+3;
		for(int rm=0;rm<i;++rm){
			BIT[++Bidx].resize(len);
			Bid[i][rm]=Bidx;
		}
		for(int j=1;j<=n;++j){
			Add(Bid[i][j%i],Get_pos(i,j),a[j]);
		}
	}
	//return 0;
	pw[0][0]=pw[1][0]=1;
	pw[0][1]=Base;
	pw[1][1]=ksm(Base,mod-2);
	for(int i=1;i<=n;++i){
		pw[0][i]=(__int128)pw[0][i-1]*Base%mod;
		pw[1][i]=(__int128)pw[1][i-1]*pw[1][1]%mod;
		assert((__int128)pw[0][i]*pw[1][i]%mod==1);
	}
	for(int i=1;i<=n;++i){
		__int128 tmppp=a[i];
		if(tmppp<0){
			tmppp=-tmppp;
			tmppp%=mod;
			tmppp=mod-tmppp;
		}
		tmppp%=mod;
		aDD(i,(__int128)a[i]*pw[0][n-i]%mod);
	}
	while(q--){
		//cout<<q<<endl;
		char type;
		type=getchar();
		while(type!='Q'&&type!='U') type=getchar();
		if(type=='U'){
			int pos;
			long long tar;
			pos=read();
			tar=read();
			long long del=tar-a[pos];
			a[pos]=tar;
			dif[pos]+=del;
			Min_Modify(pos,del);
			if(pos!=n) dif[pos+1]-=del;
			if(del<0){
				del=-del;
				del%=mod;
				del=mod-del;
			}
			del%=mod;
			aDD(pos,(__int128)del*pw[0][n-pos]%mod);
		}
		else{
			int l,r,ool,oor;
			l=read();
			r=read();
			ool=read();
			oor=read();
			int k=r-l+1;
			k=Gcd(k,Primagen::Ask(ool,oor));
			//cout<<k<<endl;
			if(k<=Blim){
				bool flag=true;
				long long tar=Ask(Bid[k][l%k],Get_pos(k,l)-1)-Ask(Bid[k][l%k],Get_pos(k,r-k+1));
				for(int i=1;i<k;++i){
					/*if(i&&Ask(Bid[k][(l+i)%k],Get_pos(k,l+i)-1)!=Ask(Bid[k][(l+i)%k],Get_pos(k,r-k+1+i))){
						flag=false;
						break;
					}*/
					if(Ask(Bid[k][(l+i)%k],Get_pos(k,l+i)-1)-Ask(Bid[k][(l+i)%k],Get_pos(k,r-k+1+i))!=tar){
						flag=false;
						break;
					}
					/*long long sum=0;
					for(int j=l+i;j<=r;j+=k){
						if()
					}*/
				}
				if(flag){
					puts("YES");
				}
				else{
					puts("NO");
				}
			}
			else{
				long long sum=0,sum2=0;
				long long lst=aSK(r);
				for(int i=r-k;i>=l-1;i-=k){
					__int128 tmp=aSK(i);
					__int128 lt=tmp;
					tmp=(lst+mod-tmp)%mod;
					tmp=tmp*pw[1][n-i-k]%mod;
					sum=(sum+tmp)%mod;
					lst=lt;
					sum2+=a[i+1]+mod;
					sum2%=mod;
				}
				__int128 coef;
				coef=pw[0][k]+mod-1;
				coef=coef*ksm(Base-1,mod-2)%mod;
				//assert(coef==1);
				coef=coef*sum2%mod;
				if(coef==sum){
					puts("YES");
				}
				else{
					puts("NO");
				}
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4056kb

input:

6 4 5
1 1 4 5 1 4
3 3 2 4
Q 1 5 1 2
Q 2 5 3 4
U 5 2
Q 1 6 1 2
Q 2 5 3 4

output:

YES
NO
NO
YES

result:

wrong answer 1st words differ - expected: 'Yes', found: 'YES'