QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350159#7782. Ursa Minor275307894aTL 532ms37676kbC++144.0kb2024-03-10 14:50:152024-03-10 14:50:17

Judging History

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

  • [2024-03-10 14:50:17]
  • 评测
  • 测评结果:TL
  • 用时:532ms
  • 内存:37676kb
  • [2024-03-10 14:50:15]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*50+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=2e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int A[N],B[N],op[N],l[N],r[N],k[N],n,m,q,st[20][N],ans[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
ll goal[N];
namespace bit{
	ll f[N];void add(int x,int w){while(x<=n) f[x]+=w,x+=x&-x;}
	ll qry(int x){ll ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
}
ll pw[N],iw[N];const int bas=137;
const int ivb=mpow(bas-1);
namespace Block1{
	ll f[N],g[N];int BB;
	void build(){
		BB=sqrt(n);
		for(int i=0;i<=n/BB;i++){
			int fr=max(1,i*BB),en=min(n,i*BB+BB-1);
			for(int i=fr;i<=en;i++) f[i]=A[i]*pw[i]%mod;
			for(int i=fr+1;i<=en;i++) f[i]+=f[i-1];
			g[i]=f[en];if(i) g[i]+=g[i-1];
		}
	}
	void add(int x,ll w){
		int X=x/BB;
		for(int i=X;i<=n/BB;i++) g[i]+=w;
		for(int i=x;i<=X*BB+BB-1&&i<=n;i++) f[i]+=w;
	}
	ll qry(int x){
		return f[x]+(x/BB?g[x/BB-1]:0);
	}
}
namespace Block2{
	ll f[N],g[N];int BB;
	void build(){
		BB=sqrt(n);
		Me(f,0);Me(g,0);
	}
	void add(int x,ll w){
		f[x]+=w;g[x/BB]+=w;
	}
	ll qry(int x){
		ll ans=0;int X=x/BB;
		for(int i=0;i<X;i++) ans+=g[i];
		for(int i=X*BB;i<=x;i++) ans+=f[i];
		return ans;
	}
}
void Solve(){
	int i,j;scanf("%d%d%d",&n,&m,&q);
	for(i=1;i<=n;i++) scanf("%d",&A[i]),bit::add(i,A[i]);
	for(i=1;i<=m;i++) scanf("%d",&st[0][i]);
	for(i=1;(1<<i)<=m;i++){
		for(j=1;j+(1<<i)-1<=m;j++) st[i][j]=__gcd(st[i-1][j],st[i-1][j+(1<<i-1)]);
	}
	Mc(B,A);
	for(pw[0]=i=1;i<=n;i++) pw[i]=pw[i-1]*bas%mod;
	iw[0]=1;iw[1]=mpow(bas);for(i=2;i<=n;i++) iw[i]=iw[i-1]*iw[1]%mod;
	Block1::build();
	vector<int> ks;
	for(i=1;i<=q;i++){
		char c=Gc();while(c<'A'||c>'Z') c=Gc();
		if(c=='U'){
			op[i]=1;
			scanf("%d%d",&l[i],&k[i]);
			bit::add(l[i],-A[l[i]]);Block1::add(l[i],-A[l[i]]*pw[l[i]]%mod);
			A[l[i]]=k[i];
			bit::add(l[i],A[l[i]]);Block1::add(l[i],A[l[i]]*pw[l[i]]%mod);
		}else{
			int x,y;op[i]=2;scanf("%d%d%d%d",&l[i],&r[i],&x,&y);
			int d=__lg(y-x+1);k[i]=__gcd(r[i]-l[i]+1,__gcd(st[d][x],st[d][y-(1<<d)+1]));
			ll sum=bit::qry(r[i])-bit::qry(l[i]-1);
			if(sum%k[i]){ans[i]=2;continue;}
			goal[i]=sum/k[i]%mod*(pw[k[i]]-1)%mod*ivb%mod;
			if(1ll*k[i]*k[i]<=1ll*n*n) ks.emplace_back(k[i]);
			else{
				ll tot=0;for(j=l[i];j<=r[i];j+=k[i]) tot+=(Block1::qry(j+k[i]-1)-Block1::qry(j-1))%mod*iw[j]%mod;
				gdb(i,sum,k[i],goal[i],tot%mod);
				ans[i]=(tot%mod==goal[i]?1:2);
			} 
		}
	}
	sort(all(ks));ks.erase(unique(all(ks)),ks.end());
	for(int t:ks){
		Block2::build();Mc(A,B);
		for(i=1;i<=n;i++) Block2::add(i,A[i]*pw[i%t]%mod);
		for(int i=1;i<=q;i++){
			if(op[i]==1){
				Block2::add(l[i],-A[l[i]]*pw[l[i]%t]%mod);
				A[l[i]]=k[i];
				Block2::add(l[i],A[l[i]]*pw[l[i]%t]%mod);
			}else if(!ans[i]&&k[i]==t){
				// gdb(i,(Block2::qry(r[i])-Block2::qry(l[i]-1))%mod,goal[i]);
				ans[i]=((Block2::qry(r[i])-Block2::qry(l[i]-1))%mod!=goal[i])+1;
			}
		}
	}
	for(i=1;i<=q;i++) if(op[i]==2) puts(ans[i]^2?"Yes":"No");
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

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

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 75ms
memory: 33584kb

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:

ok 100554 tokens

Test #4:

score: 0
Accepted
time: 60ms
memory: 35568kb

input:

1 200000 200000
998244353
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100240 tokens

Test #5:

score: 0
Accepted
time: 40ms
memory: 37676kb

input:

6 131072 200000
0 0 0 0 1000000000 1000000000
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
N...

result:

ok 100021 tokens

Test #6:

score: 0
Accepted
time: 532ms
memory: 37580kb

input:

200000 200000 200000
490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
N...

result:

ok 187340 tokens

Test #7:

score: -100
Time Limit Exceeded

input:

200000 200000 200000
360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531...

output:


result: