QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369177 | #7782. Ursa Minor | Perta | TL | 2982ms | 130756kb | C++14 | 3.9kb | 2024-03-27 21:25:47 | 2024-03-27 21:25:50 |
Judging History
answer
#include<bits/stdc++.h>
#define int Int
using namespace std;
typedef __int128 Int;
inline int read()
{
int x=0;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x;
}
const int N=2e5+10,M=450,maxj=18;
const int base=10457,mod=1000000000000001323ll;
int n,m,K,q,a[N],b[N],s0[M][M];
int lg[N],GCD[19][N];
int pw[N],pre[N],inv[N],sum[M][M];
int rb[N],bel[N],tot1[N],tot2[N];
vector<int>d[N];
inline void upd(int &x,int y) {x+=y;x=(x>=mod)?x-mod:x;}
inline int add(int x,int y) {upd(x,y);return x;}
int ksm(int x,int 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=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]],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]);
}
int S0(int x,int l,int r)
{
int res=0;
for(int i=((l-1)/x+1)*x;i<=r;i+=x) upd(res,a[i]);
return res;
}
int query0(int x,int l,int r)
{
int 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;
}
int S1(int x,int l,int r)
{
int res=0;
for(int i=l,j=l%x;i<=r;i++,j=(j+1==x?0:j+1)) upd(res,a[i]*pw[j]%mod);
return res;
}
int query2(int x) {return add(tot1[x],tot2[bel[x]]);}
int S2(int l,int r) {return add(query2(r),mod-query2(l-1));}
signed 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]=base*pw[i-1]%mod,pre[i]=add(pw[i],pre[i-1]),inv[i]=ksm(pw[i],mod-2);
n=read(),m=read(),q=read();
K=1;
for(int i=1;i<=n;i++)
if(i*i>n) {K=i-1;break;}
// K=__builtin_sqrt(n);
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) GCD[0][i]=read();
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",&op);
l=read(),r=read();
// 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)),ned=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=S2(l,r)*inv[l/k*k]%mod;
else
{
S=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,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: 104ms
memory: 35316kb
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: 104ms
memory: 30492kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 219ms
memory: 54464kb
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: 84900kb
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: 151ms
memory: 84904kb
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: 2368ms
memory: 130068kb
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: 0
Accepted
time: 2322ms
memory: 130512kb
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:
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 199985 tokens
Test #8:
score: 0
Accepted
time: 2410ms
memory: 130756kb
input:
200000 200000 200000 793134805 922104801 158394038 993313213 77527653 992889267 148461787 499165677 132176015 189185554 783374975 332147281 923925325 371040161 393285793 437388761 138662855 212488140 265392646 498903298 578518594 550390771 960084339 408548934 56106823 814997309 456913457 300689692 1...
output:
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 No No No No No No No No No No No No Yes 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 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...
result:
ok 200000 tokens
Test #9:
score: 0
Accepted
time: 2374ms
memory: 127732kb
input:
200000 200000 200000 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037...
output:
No No No No Yes No Yes No No No No Yes No No No Yes No Yes No No No No No No No No No No No No No No Yes No No No No No No No Yes No No Yes No Yes No Yes No Yes No No No No Yes No No Yes No No No No No No No No Yes No Yes No No No No Yes No Yes No No Yes No Yes No No No Yes No No No No No No No No N...
result:
ok 199977 tokens
Test #10:
score: 0
Accepted
time: 2982ms
memory: 129084kb
input:
200000 200000 200000 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606...
output:
No No No Yes No No No No No No No No No No No No Yes No No Yes No No No No No No No No No No Yes No No No No Yes No No No No No No No No Yes No No No No No No No No No No No No Yes No No No Yes 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 Yes No No No No No No N...
result:
ok 100329 tokens
Test #11:
score: -100
Time Limit Exceeded
input:
200000 199999 200000 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886...
output:
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 No No No No No No No No No No No No No No No No No No No No No No...