QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369175 | #7782. Ursa Minor | Perta | RE | 100ms | 34116kb | C++14 | 3.9kb | 2024-03-27 21:24:23 | 2024-03-27 21:24:24 |
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();
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: 100ms
memory: 34116kb
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: -100
Runtime Error
input:
1 1 1 0 1 Q 1 1 1 1