QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382986#7782. Ursa MinorGraphcityWA 1654ms340992kbC++203.1kb2024-04-08 20:43:522024-04-08 20:43:52

Judging History

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

  • [2024-04-08 20:43:52]
  • 评测
  • 测评结果:WA
  • 用时:1654ms
  • 内存:340992kb
  • [2024-04-08 20:43:52]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=2e5+2,B=400;
const int base=19260817,Mod=1e9+7;

inline int Pow(int x,int y)
{
    int res=1;
    while(y)
    {
        if(y&1) res=1ll*res*x%Mod;
        x=1ll*x*x%Mod,y>>=1;
    }
    return res;
}

int n,m,q,a[Maxn+5],b[Maxn+5],st[Maxn+5][20],pw[Maxn+5];
int L[Maxn+5],R[Maxn+5],idx[Maxn+5],iv[Maxn+5],tot;
inline int Get(int l,int r)
{int len=__lg(r-l+1); return __gcd(st[l][len],st[r-(1<<len)+1][len]);}

struct Block
{
    int sum[B+5],a[Maxn+5];
    inline void Upd(int x,int y)
    {sum[idx[x]]=(1ll*sum[idx[x]]-a[x]+y+Mod)%Mod,a[x]=y;}
    inline int Count(int x)
    {
        if(x==0) return 0;
        int res=0; For(i,1,idx[x]-1) res=(res+sum[i])%Mod;
        For(i,L[idx[x]],x) res=(res+a[i])%Mod; return res;
    }
} T[B+2];

struct Fenwick
{
    int sum[Maxn+5],pr[Maxn+5],a[Maxn+5];
    inline void Upd(int x,int y)
    {
        int dlt=(y-a[x]+Mod)%Mod; a[x]=y;
        For(i,x,R[idx[x]]) pr[i]=(pr[i]+dlt)%Mod;
        For(i,idx[x],tot) sum[i]=(sum[i]+dlt)%Mod;
    }
    inline int Count(int x) {return x==0?0:(sum[idx[x]-1]+pr[x])%Mod;}
} F;

struct BIT
{
    int t[Maxn+5];
    #define lowbit(x) (x&-x)
    inline void Add(int x,int y) {while(x<=n) t[x]=(t[x]+y)%Mod,x+=lowbit(x);}
    inline int Count(int x) {int res=0; while(x) res=(res+t[x])%Mod,x-=lowbit(x); return res;}
} BT;

int main()
{
    // freopen("1.in","r",stdin);

    ios::sync_with_stdio(false);
    cin>>n>>m>>q; For(i,1,n) cin>>a[i];
    pw[0]=1; For(i,1,Maxn) pw[i]=1ll*pw[i-1]*base%Mod;
    iv[0]=1; For(i,1,Maxn) iv[i]=Pow(pw[i],Mod-2);
    For(i,1,m) cin>>b[i],st[i][0]=b[i];
    For(j,1,19) for(int i=1;i+(1<<j)-1<=m;++i)
        st[i][j]=__gcd(st[i][j-1],st[i+(1<<j-1)][j-1]);
    for(int i=1;i<=n;i+=B) L[++tot]=i,R[tot]=min(n,i+B-1);
    For(i,1,tot) For(j,L[i],R[i]) idx[j]=i;
    For(i,1,n) For(j,1,B) T[j].Upd(i,1ll*a[i]*pw[i%j]%Mod);
    For(i,1,n) BT.Add(i,a[i]),F.Upd(i,1ll*a[i]*pw[i]%Mod);
    int it=0; while(q--)
    {
        char ch; int l,r,x,y; cin>>ch;
        if(ch=='U')
        {
            cin>>x>>y; BT.Add(x,(y-a[x]+Mod)%Mod),a[x]=y;
            For(i,1,B) T[i].Upd(x,1ll*y*pw[x%i]%Mod);
            F.Upd(x,1ll*y*pw[x]%Mod);
        }
        if(ch=='Q')
        {
            cin>>l>>r>>x>>y; int k=__gcd(Get(x,y),r-l+1);
            int sum=(BT.Count(r)-BT.Count(l-1)+Mod)%Mod;
            sum=1ll*sum*Pow(k,Mod-2)%Mod;
            sum=1ll*sum*(pw[k]-1)%Mod*Pow(base-1,Mod-2)%Mod;
            int all=0;
            if(k<=B) all=(T[k].Count(r)-T[k].Count(l-1)+Mod)%Mod;
            else
            {
                For(i,0,n/k)
                {
                    int a=i*k,b=(i+1)*k-1; a=max(a,l),b=min(b,r);
                    if(a<=b)
                    {
                        int now=(F.Count(b)-F.Count(a-1)+Mod)%Mod;
                        all=(all+1ll*now*iv[i*k]%Mod)%Mod;
                    }
                }
            }
            puts(sum==all?"Yes":"No");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 14012kb

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: 32ms
memory: 13960kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 465ms
memory: 15228kb

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: 255ms
memory: 27328kb

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: 256ms
memory: 24496kb

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: 1654ms
memory: 340992kb

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
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
Yes
No
Yes
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
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
...

result:

wrong answer 15th words differ - expected: 'Yes', found: 'No'