QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281470#7782. Ursa Minorucup-team197#WA 117ms17812kbC++143.8kb2023-12-10 06:23:222023-12-10 06:23:22

Judging History

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

  • [2023-12-10 06:23:22]
  • 评测
  • 测评结果:WA
  • 用时:117ms
  • 内存:17812kb
  • [2023-12-10 06:23:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=2e9-57;
const int N=2e5+5;
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
int n,m,q;
ll bit[N];
void upd(int id,ll v){
	for(int i=id; i<=n ;i+=i&-i) bit[i]+=v;
}
ll qry(int id){
	ll res=0;
	for(int i=id; i>=1 ;i-=i&-i) res+=bit[i];
	return res;
}
ll t[N][19];
int lg[N];
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int gett(int l,int r){
	int k=lg[r-l+1];
	return gcd(t[l][k],t[r-(1<<k)+1][k]);
}
ll g;
const int mg=400;
ll pg[mg+5];
ll pf[mg+5];
ll ia[N],a[N],b[N],c[N];

char tp[N];
int ql[N],qr[N],qt[N];
ll tar[N];//sum a mod
bool ans[N];

bool st[mg+5];

ll bin[N];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m >> q;
	{
		mt19937 rng(226);
		g=uniform_int_distribution<ll>(0,mod-1)(rng);
		g=2;
		pg[0]=pf[0]=1;
		for(int i=1; i<=mg ;i++){
			pg[i]=pg[i-1]*g%mod;
			pf[i]=(pf[i-1]+pg[i])%mod;
		}
	}
	for(int i=0; i<n ;i++){
		cin >> ia[i];
		a[i]=ia[i];
		upd(i+1,a[i]);
	}
	for(int i=1; i<=m ;i++){
		cin >> t[i][0];
		if(i>=2) lg[i]=lg[i/2]+1;
	}
	for(int i=1; (1<<i)<=m ;i++){
		for(int j=1; j+(1<<i)<=m+1 ;j++){
			t[j][i]=gcd(t[j][i-1],t[j+(1<<(i-1))][i-1]);
		}
	}
	for(int i=1; i<=q ;i++){
		cin >> tp[i];
		if(tp[i]=='U'){
			cin >> ql[i] >> qt[i];
			ql[i]--;
			int j=ql[i];
			upd(j+1,qt[i]-a[j]);
			a[j]=qt[i];
		}
		else{
			int l,r,tl,tr;cin >> l >> r >> tl >> tr;
			ans[i]=true;
			tar[i]=qry(r)-qry(l-1);
			int m=r-l+1;
			int t=gcd(gett(tl,tr),m);
			ql[i]=l-1;
			qr[i]=r-1;
			qt[i]=t;
			tar[i]=(tar[i]%mod+mod)%mod;
			tar[i]=tar[i]*pw(t,mod-2)%mod;
			if(t<=mg) st[t]=true;
			//cout << "frog " << i << ' ' << tar[i] << ' ' <<ql[i] << ' ' << qr[i] << ' ' << qt[i] << endl;
		}
	}
	for(int i=1; i<=mg ;i++){
		if(!st[i]) continue;
		int bc=(n-1)/mg+1;
		for(int j=0; j<bc ;j++) bin[j]=0;
		for(int j=0; j<n ;j++) a[j]=ia[j]*pg[j%i]%mod;
		for(int j=0; j<n ;j++) bin[j/mg]=(bin[j/mg]+a[j])%mod;
		for(int qq=1; qq<=q ;qq++){
			if(tp[qq]=='U'){//O(1)
				int j=ql[qq];
				bin[j/mg]=(bin[j/mg]+qt[qq]*pg[j%i]+mod-a[j])%mod;
				a[j]=qt[qq]*pg[j%i]%mod;
			}
			else if(qt[qq]==i){
				int l=ql[qq],r=qr[qq];
				int bl=l/mg;
				int br=r/mg;
				ll res=0;
				if(bl==br){
					for(int j=l; j<=r ;j++) res+=a[j];
					res%=mod;
				}
				else{
					for(int j=l; j<(bl+1)*mg ;j++) res+=a[j];
					for(int j=bl+1; j<br ;j++) res+=bin[j];
					for(int j=br*mg; j<=r ;j++) res+=a[j];
					res%=mod;
				}
				ll opt=tar[qq]*pf[i-1]%mod;
				if(res!=opt) ans[qq]=false;
			}
		}
	}
	for(int i=0; i<mg ;i++) b[i]=0;
	for(int i=0; i<n ;i++){
		a[i]=ia[i];
	}
	ll s=0;
	for(int i=n-1; i>=0 ;i--){
		s=(s*pg[1]+a[i])%mod;
		if(i+mg<n) s=(s+mod-a[i+mg]*pg[mg]%mod)%mod;
		b[i]=s;
	}
	for(int i=1; i<=q ;i++){
		if(tp[i]=='U'){
			int p=ql[i];
			int v=qt[i];
			for(int j=0; j<=min(p,mg-1) ;j++){
				b[p-j]=(b[p-j]+pg[j]*(v+mod-a[p]))%mod;
			}
			a[p]=v;
		}
		else if(qt[i]>mg){
			int l=ql[i];
			int r=qr[i]+1;
			int t=qt[i];
			int m=r-l;
			/*s=b[l];
			for(int i=r-1; i>=r-mg ;i--){
				s=(s*pg[1]+a[i])%mod;
				s=(s+mod-a[i+mg-m]*pg[mg])%mod;
				c[i]=s;
			}*/
			for(int j=0; j<=(t-1)/mg ;j++){
				int st=j*mg;
				if(st+mg>t) st=t-mg;
				ll res=0;
				for(int k=0; k<m ;k+=t) res+=b[l+st+k];
				res%=mod;
				ll opt=tar[i]*pf[mg-1]%mod;
				if(res!=opt){
					ans[i]=false;
					break;
				}
			}
		}
		/*cout << "OUT " << i << endl;
		for(int j=0; j<n ;j++){
			cout << b[j] << ' ';
		}
		cout << endl;*/
	}
	
	for(int i=1; i<=q ;i++){
		if(tp[i]=='Q'){
			if(ans[i]) cout << "Yes\n";
			else cout << "No\n";
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 17800kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: -100
Wrong Answer
time: 117ms
memory: 17812kb

input:

2000 2000 200000
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...

output:

Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No...

result:

wrong answer 563rd words differ - expected: 'No', found: 'Yes'