QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369216#7782. Ursa MinorPertaRE 90ms32536kbC++143.6kb2024-03-27 22:08:022024-03-27 22:08:04

Judging History

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

  • [2024-03-27 22:08:04]
  • 评测
  • 测评结果:RE
  • 用时:90ms
  • 内存:32536kb
  • [2024-03-27 22:08:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=500,maxj=20;
const int base=233,mod=1e9+9;
int n,m,K,q,a[N],b[N],s0[M][M];
int lg[N],GCD[21][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=1ll*res*x%mod;
        x=1ll*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]);
}
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]]);
        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));
    }
    else res=S0(x,l,r);
    return res;
}
int S1(int x,int l,int r)
{
    int res=0;
    for(int i=l;i<=r;i++)
        upd(res,1ll*a[i]*pw[i%x]%mod);
    // for(int i=l,j=l%x;i<=r;i++,j=(j+1==x?0:j+1)) upd(res,1ll*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));}
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]=1ll*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)),ned=1ll*query0(k,l,r)*pre[k-1]%mod,S=0;
            // assert(k);
            if(bel[l]==bel[r]) S=S1(k,l,r);
            else if(k<=K)
                // if(bel[l]==bel[r]) S=S1(k,l,r);
                // else
                {
                    S=S1(k,l,rb[bel[l]]);
                    for(int i=bel[l]+1;i<bel[r];i++) upd(S,sum[k][i]);
                    upd(S,S1(k,rb[bel[r]-1]+1,r));
                }
            else
            {
                if(l/k==r/k)
                    S=1ll*S2(l,r)*inv[l/k*k]%mod;
                else
                {
                    int Mx=((l-1)/k+1)*k;
                    S=1ll*S2(l,(Mx-1)*inv[l/k*k])%mod;
                    for(int i=Mx,j=i/k*k;i<=r;i+=k)
                        upd(S,1ll*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: 26ms
memory: 17232kb

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: 31ms
memory: 18668kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 90ms
memory: 27428kb

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: 86ms
memory: 32536kb

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: 72ms
memory: 31240kb

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
Runtime Error

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:


result: