QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370020#7782. Ursa MinorPertaWA 1455ms46936kbC++144.3kb2024-03-28 21:10:182024-03-28 21:10:19

Judging History

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

  • [2024-03-28 21:10:19]
  • 评测
  • 测评结果:WA
  • 用时:1455ms
  • 内存:46936kb
  • [2024-03-28 21:10:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=450,maxj=18;
const int base[2]={233,127},mod[2]={1000000789,1000000009};
int n,m,K,q,a[N],b[N],s0[2][M][M];
int lg[N],GCD[19][N];
int pw[2][N],pre[2][N],inv[2][N],sum[2][M][M];
int rb[N],bel[N],tot1[2][N],tot2[2][N];
vector<int>d[N];
inline void upd(bool p,int &x,int y) {x+=y;x=(x>=mod[p])?x-mod[p]:x;}
inline int add(bool p,int x,int y) {upd(p,x,y);return x;}
int ksm(bool p,int x,int y)
{
    int res=1;
    for(;y;y>>=1)
    {
        if(y&1) res=1ll*res*x%mod[p];
        x=1ll*x*x%mod[p];
    }
    return res;
}
void add(bool p,int x)
{
    for(int v:d[x]) upd(p,s0[p][v][bel[x]],a[x]);
    int T=1ll*a[x]*pw[p][x]%mod[p];
    for(int i=x;i<=rb[bel[x]];i++) upd(p,tot1[p][i],T);
    for(int i=bel[x]+1;i<=bel[n];i++) upd(p,tot2[p][i],T);
    for(int i=1;i<=K;i++)
        upd(p,sum[p][i][bel[x]],1ll*a[x]*pw[p][x%i]%mod[p]);
}
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(bool p,int x,int l,int r)
{
    int res=0;
    for(int i=((l-1)/x+1)*x;i<=r;i+=x) upd(p,res,a[i]);
    return res;
}
int query0(bool p,int x,int l,int r)
{
    int res=0;
    if(x<=K&&bel[l]<bel[r])
    {
        res=S0(p,x,l,rb[bel[l]]);
        // cerr<<res<<endl;
        for(int i=bel[l]+1;i<bel[r];i++) upd(p,res,s0[p][x][i]);
        upd(p,res,S0(p,x,rb[bel[r]-1]+1,r));
        // cerr<<res<<endl;
    }
    else res=S0(p,x,l,r);
    return res;
}
int S1(bool p,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(p,res,1ll*a[i]*pw[p][j]%mod[p]);
    return res;
}
int query2(bool p,int x) {return add(p,tot1[p][x],tot2[p][bel[x]]);}
int S2(bool p,int l,int r) {return add(p,query2(p,r),mod[p]-query2(p,l-1));}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("a.out","w",stdout);
    for(int i=2;i<N;i++) lg[i]=lg[i>>1]+1;
    for(int p=0;p<2;p++)
    {
        pw[p][0]=pre[p][0]=inv[p][0]=1;
        for(int i=1;i<N;i++)
            pw[p][i]=1ll*base[p]*pw[p][i-1]%mod[p],pre[p][i]=add(p,pw[p][i],pre[p][i-1]),inv[p][i]=ksm(p,pw[p][i],mod[p]-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++)
        for(int p=0;p<2;p++) add(p,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')
        {
            int x=a[l];
            for(int p=0;p<2;p++)
                a[l]=add(p,r,mod[p]-x),add(p,l);
            a[l]=r;
        }
        else
        {
            scanf("%d%d",&s,&t);
            int k=__gcd(r-l+1,query(s,t));
            bool flag=1;
            for(int p=0;p<2&&flag;p++)
            {
                int ned=1ll*query0(p,k,l,r)*pre[p][k-1]%mod[p],S=0;
                // cerr<<k<<" "<<ned<<endl;
                if(k<=K)
                    if(bel[l]==bel[r]) S=S1(p,k,l,r);
                    else
                    {
                        S=S1(p,k,l,rb[bel[l]]);
                        // cerr<<S<<endl;
                        for(int i=bel[l]+1;i<bel[r];i++) upd(p,S,sum[p][k][i]);
                        // cerr<<S<<endl;
                        upd(p,S,S1(p,k,rb[bel[r]-1]+1,r));
                    }
                else
                {
                    if(l/k==r/k)
                        S=1ll*S2(p,l,r)*inv[p][l/k*k]%mod[p];
                    else
                    {
                        S=1ll*S2(p,l,((l-1)/k+1)*k-1)*inv[p][l/k*k]%mod[p];
                        for(int i=((l-1)/k+1)*k,j=i;i<=r;i+=k)
                            upd(p,S,1ll*S2(p,i,min(r,i+k-1))*inv[p][i]%mod[p]);
                    }
                }
                if(ned!=S) flag=0;
            }
            puts(flag?"Yes":"No");
        }
        // return 0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 90ms
memory: 17184kb

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

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 186ms
memory: 16500kb

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: 155ms
memory: 29232kb

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: 140ms
memory: 24300kb

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
Wrong Answer
time: 1455ms
memory: 46936kb

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:

wrong answer 1043rd words differ - expected: 'Yes', found: 'No'