QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393878 | #7782. Ursa Minor | Eric_cai | ML | 83ms | 23504kb | C++14 | 3.9kb | 2024-04-19 15:57:29 | 2024-04-19 15:57:30 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
const ll base=20080129;
const int maxn=2e5+5;
const int maxb=505;
ll gcd(ll x,ll y)
{
if(x==0 || y==0) return x+y;
return gcd(y,x%y);
}
ll qp(ll x,ll y)
{
ll ret=1;
while(y)
{
if(y&1) ret=ret*x%mod;
x=x*x%mod;
y>>=1;
}
return ret;
}
int n,m,q,num;
int id[maxn],L[maxn],R[maxn],len;
ll a[maxn],b[maxn];
ll p[maxn],sp[maxn],invp[maxn];
ll sk0[maxb][maxb],hh[maxb][maxn],skh[maxb][maxb];
ll sumah[maxn],sskah[maxb];
ll d[maxn<<2];
void pushup(int id)
{
d[id]=gcd(d[id<<1],d[id<<1|1]);
}
void update(int id,int l,int r,int x,int w)
{
if(l==r)
{
d[id]=w;
return;
}
int mid=(l+r)>>1;
if(x<=mid) update(id<<1,l,mid,x,w);
else update(id<<1|1,mid+1,r,x,w);
pushup(id);
}
int query(int id,int l,int r,int x,int y)
{
if(l>=x && r<=y) return d[id];
int mid=(l+r)>>1,ret=0;
if(x<=mid) ret=gcd(ret,query(id<<1,l,mid,x,y));
if(y>mid) ret=gcd(ret,query(id<<1|1,mid+1,r,x,y));
return ret;
}
void upd0(int x,ll w)
{
for(int i=1;i<=len;i++)
sk0[i][id[x]]=(sk0[i][id[x]]-(x%i==0)*a[x]+(x%i==0)*w)%mod;
}
ll q0(int l,int r,int k)
{
ll ret=0;
if(k>len)
{
for(int i=k;i<=n;i+=k)
ret=(ret+(i>=l && i<=r && i%k==0)*a[i])%mod;
return ret;
}
if(id[l]==id[r])
{
for(int i=l;i<=r;i++) ret=(ret+a[i]*(i%k==0))%mod;
return ret;
}
for(int i=id[l]+1;i<=id[r]-1;i++) ret=(ret+sk0[k][i])%mod;
for(int i=l;i<=R[id[l]];i++) ret=(ret+a[i]*(i%k==0))%mod;
for(int i=L[id[r]];i<=r;i++) ret=(ret+a[i]*(i%k==0))%mod;
return ret;
}
void updh(int x,ll w)
{
for(int i=1;i<=len;i++)
{
hh[i][x]=w*p[x%i]%mod;
skh[i][id[x]]=(skh[i][id[x]]-a[x]*p[x%i]+w*p[x%i])%mod;
}
}
void updah(int x,ll w)
{
for(int i=x;i<=R[id[x]];i++)
sumah[i]=(sumah[i]-a[x]*p[x]+w*p[x])%mod;
for(int i=id[x];i<=num;i++)
sskah[i]=(sskah[i]-a[x]*p[x]+w*p[x])%mod;
}
ll qah(int l,int r)
{
if(l>r) return 0;
if(id[l]==id[r]) return (sumah[r]-sumah[l-1]*(id[l]==id[l-1]))%mod;
return (sskah[id[r]-1]-sskah[id[l]]+sumah[R[id[l]]]-sumah[l-1]*(id[l]==id[l-1])+sumah[r])%mod;
}
ll qh(int l,int r,int k)
{
ll ret=0;
if(k<=len)
{
if(id[l]==id[r])
{
for(int i=l;i<=r;i++) ret=(ret+hh[k][i])%mod;
return ret;
}
for(int i=id[l]+1;i<=id[r]-1;i++) ret=(ret+skh[k][i])%mod;
for(int i=l;i<=R[id[l]];i++) ret=(ret+hh[k][i])%mod;
for(int i=L[id[r]];i<=r;i++) ret=(ret+hh[k][i])%mod;
return ret;
}
int ql,qr;
ll ww=0;
for(int i=0;i<=n;i+=k)
{
ql=max(l,i),qr=min(r,i+k-1);
ret=(ret+qah(ql,qr)*invp[i])%mod;
}
return ret;
}
int main()
{
//freopen("circle.in","r",stdin);
//freopen("circle.out","w",stdout);
char opt;
ll x,w,l,r,k,s,t;
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++)
{
cin>>b[i];
update(1,1,m,i,b[i]);
}
invp[0]=p[0]=sp[0]=1;
for(int i=1;i<=n;i++)
{
p[i]=p[i-1]*base%mod;
invp[i]=qp(p[i],mod-2);
sp[i]=(p[i]+sp[i-1])%mod;
}
len=sqrt(n);
for(int i=1;i<=n;i++) id[i]=(i-1)/len+1,L[i]=1e9;
for(int i=1;i<=n;i++)
L[id[i]]=min(L[id[i]],i),R[id[i]]=max(R[i],i),num=max(id[i],num);
for(int i=1;i<=len;i++)
for(int j=1;j<=n;j++)
{
hh[i][j]=a[j]*p[j%i]%mod;
skh[i][id[j]]=(skh[i][id[j]]+a[j]*p[j%i])%mod;
sk0[i][id[j]]=(sk0[i][id[j]]+a[j]*(j%i==0))%mod;
}
for(int i=1;i<=num;i++)
{
sumah[L[i]]=a[L[i]]*p[L[i]]%mod;
for(int j=L[i]+1;j<=R[i];j++) sumah[j]=(sumah[j-1]+a[j]*p[j])%mod;
sskah[i]=(sumah[R[i]]+sskah[i-1])%mod;
}
int sss;
for(int i=1;i<=q;i++)
{
cin>>opt;
if(opt=='U')
{
cin>>x>>w;
w%=mod;
upd0(x,w),updh(x,w),updah(x,w);
a[x]=w;
}
if(opt=='Q')
{
cin>>l>>r>>s>>t;
k=gcd((r-l+1),query(1,1,m,s,t));
if(((q0(l,r,k)*sp[k-1])%mod+mod)%mod==(qh(l,r,k)%mod+mod)%mod) cout<<"Yes\n";
else cout<<"No\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18164kb
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: 3672kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 74ms
memory: 5088kb
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: 83ms
memory: 9396kb
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: 53ms
memory: 23504kb
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: -100
Memory Limit Exceeded
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...