QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369170 | #7782. Ursa Minor | Perta | WA | 159ms | 32488kb | C++14 | 3.6kb | 2024-03-27 21:17:00 | 2024-03-27 21:17:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 Int;
const int N=2e5+10,M=450,maxj=18;
const ll base=10457,mod=1000000000000001323ll;
int n,m,K,q,a[N],b[N],rb[N],bel[N];
int lg[N],GCD[19][N];
ll pw[N],pre[N],inv[N],s0[M][M],sum[M][M];
ll tot1[N],tot2[N];
vector<int>d[N];
inline void upd(ll &x,ll y) {x+=y;x=(x>=mod)?x-mod:x;}
inline ll add(ll x,ll y) {upd(x,y);return x;}
ll ksm(Int x,ll y)
{
Int res=1;
for(;y;y>>=1)
{
if(y&1) res=res*x%mod;
x=x*x%mod;
}
return res;
}
void add(int x)
{
for(int v:d[x]) upd(s0[v][bel[x]],a[x]);
int T=1ll*a[x]*pw[x]%mod;
for(int i=x;i<=rb[bel[x]];i++) upd(tot1[i],T);
for(int i=bel[x]+1;i<=bel[n];i++) upd(tot2[i],T);
for(int i=1;i<=K;i++)
upd(sum[i][bel[x]],1ll*a[x]*pw[x%i]%mod);
}
int query(int l,int r)
{
int p=lg[r-l+1];
return __gcd(GCD[p][l],GCD[p][r-(1<<p)+1]);
}
ll S0(int x,int l,int r)
{
ll res=0;
for(int i=((l-1)/x+1)*x;i<=r;i+=x) upd(res,a[i]);
return res;
}
ll query0(int x,int l,int r)
{
ll res=0;
if(x<=K&&bel[l]<bel[r])
{
res=S0(x,l,rb[bel[l]]);
// cerr<<res<<endl;
for(int i=bel[l]+1;i<bel[r];i++) upd(res,s0[x][i]);
upd(res,S0(x,rb[bel[r]-1]+1,r));
// cerr<<res<<endl;
}
else res=S0(x,l,r);
return res;
}
ll S1(int x,int l,int r)
{
ll res=0;
for(int i=l,j=l%x;i<=r;i++,j=(j+1==x?0:j+1)) upd(res,(Int)a[i]*pw[j]%mod);
return res;
}
ll query2(int x) {return add(tot1[x],tot2[bel[x]]);}
ll S2(int l,int r) {return add(query2(r),mod-query2(l-1));}
int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
pw[0]=pre[0]=inv[0]=1;
for(int i=2;i<N;i++) lg[i]=lg[i>>1]+1;
for(int i=1;i<N;i++)
pw[i]=(Int)base*pw[i-1]%mod,pre[i]=add(pw[i],pre[i-1]),inv[i]=ksm(pw[i],mod-2);
scanf("%d%d%d",&n,&m,&q);
K=__builtin_sqrt(n);
for(int i=1;i<=n;i++) scanf("%d",a+i);
for(int i=1;i<=m;i++) scanf("%d",GCD[0]+i);
for(int i=1;i<=maxj;i++)
for(int j=1;(1<<i)+j-1<=m;j++)
GCD[i][j]=__gcd(GCD[i-1][j],GCD[i-1][(1<<(i-1))+j]);
for(int i=1;i<=K;i++)
for(int j=i;j<=n;j+=i) d[j].push_back(i);
for(int i=1;i<=n;i++)
bel[i]=i/K,rb[bel[i]]=i;
// cerr<<"He "<<endl;
// return 0;
// cerr<<K<<endl;
for(int i=1;i<=n;i++) add(i);
// cerr<<"He"<<endl;
// return 0;
char op;
int l,r,s,t;
while(q--)
{
scanf("\n%c%d%d",&op,&l,&r);
if(op=='U')
a[l]=add(r,mod-a[l]),add(l),a[l]=r;
else
{
scanf("%d%d",&s,&t);
int k=__gcd(r-l+1,query(s,t));
ll ned=(Int)query0(k,l,r)*pre[k-1]%mod,S=0;
// cerr<<k<<" "<<ned<<endl;
if(k<=K)
if(bel[l]==bel[r]) S=S1(k,l,r);
else
{
S=S1(k,l,rb[bel[l]]);
// cerr<<S<<endl;
for(int i=bel[l]+1;i<bel[r];i++) upd(S,sum[k][i]);
// cerr<<S<<endl;
upd(S,S1(k,rb[bel[r]-1]+1,r));
}
else
{
if(l/k==r/k)
S=(Int)S2(l,r)*inv[l/k*k]%mod;
else
{
S=(Int)S2(l,((l-1)/k+1)*k-1)*inv[l/k*k]%mod;
for(int i=((l-1)/k+1)*k,j=i;i<=r;i+=k)
upd(S,(Int)S2(i,min(r,i+k-1))*inv[i]%mod);
}
}
puts(ned==S?"Yes":"No");
}
// return 0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 99ms
memory: 20280kb
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: 102ms
memory: 17416kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 159ms
memory: 26292kb
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: 151ms
memory: 30788kb
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: -100
Wrong Answer
time: 142ms
memory: 32488kb
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No 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 No No No No No No No No Yes No Yes No No No No No ...
result:
wrong answer 7th words differ - expected: 'Yes', found: 'No'