QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511355#7782. Ursa Minori_am_noobWA 468ms225612kbC++144.5kb2024-08-09 19:38:232024-08-09 19:38:24

Judging History

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

  • [2024-08-09 19:38:24]
  • 评测
  • 测评结果:WA
  • 用时:468ms
  • 内存:225612kb
  • [2024-08-09 19:38:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using pii=pair<int,int>;
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())

const int mod=1000'000'007;
int add(int x, int y){x+=y; if(x>=mod) x-=mod; return x;}
int sub(int x, int y){x-=y; if(x<0) x+=mod; return x;}
int mul(int x, int y){return ((ll)x)*y%mod;}
int Pow(int x, ll y=mod-2){int res=1; for(; y; x=mul(x,x),y>>=1) if(y&1) res=mul(res,x); return res;}

const int N=200005,K=1<<8;
constexpr int block(int x){
    return x>>8;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int seed[N],pw[N],ipw[N];

struct DS{
    int k,val[N],big[N/K+5],tot;
    void init(){
        int cur=0;
        tot=0;
        for(int i=0; i<k; ++i) tot=add(tot,seed[i]);
    }
    void set(int p, int x){
        big[block(p)]=sub(big[block(p)],val[p]);
        val[p]=mul(x,seed[p%k]);
        big[block(p)]=add(big[block(p)],val[p]);
    }
    int sum(int r){
        if(r<0) return 0;
        int res=0;
        int b=block(r);
        for(int i=0; i<b; ++i) res=add(res,big[i]);
        for(int i=b*K; i<=r; ++i) res=add(res,val[i]);
        return res;
    }
}ds[K];

struct BIT{
    ll bit[N];
    void add(int p, int x){
        for(++p; p<N; p+=p&-p) bit[p]+=x;
    }
    ll sum(int r){
        ll res=0;
        for(++r; r; r-=r&-r) res+=bit[r];
        return res;
    }
}bit;

struct DS2{
    int val[N+K],big[N/K+5],pref[N+K],pref_big[N/K+5];
    void build_big(){
        for(int i=0; i<N/K+5-1; ++i) pref_big[i+1]=add(pref_big[i],big[i]);
    }
    void build(int b){
        pref[b*K]=val[b*K];
        for(int i=b*K; i+1<(b+1)*K; ++i) pref[i]=add(pref[i-1],val[i]);
    }
    void set(int p, int x){
        big[block(p)]=sub(big[block(p)],val[p]);
        val[p]=mul(x,pw[p]);
        big[block(p)]=add(big[block(p)],val[p]);
        build(block(p));
        build_big();
    }
    int sum(int r){
        if(r<0) return 0;
        int b=block(r);
        int res=pref_big[b];
        res=add(res,pref[r]);
        return res;
    }
}ds2;

int n,m,q,a[N],b[N],sp[18][N];

int sp_query(int l, int r){
    r++;
    int k=__lg(r-l);
    return __gcd(sp[k][l],sp[k][r-(1<<k)]);
}

void ahcorz(){
    cin >> n >> m >> q;
    for(int i=0; i<n; ++i) cin >> a[i],bit.add(i,a[i]);
    for(int i=1; i<K; ++i){
        ds[i].k=i;
        ds[i].init();
        int cur=0;
        for(int j=0; j<n; ++j){
            ds[i].val[j]=mul(a[j],seed[cur]);
            cur++;
            if(cur>=i) cur-=i;
            ds[i].big[block(j)]=add(ds[i].big[block(j)],ds[i].val[j]);
        }
    }
    for(int i=0; i<n; ++i){
        ds2.val[i]=mul(a[i],pw[i]);
        ds2.big[block(i)]=add(ds2.big[block(i)],ds2.val[i]);
    }
    for(int i=0; i<=block(n-1); ++i) ds2.build(i);
    ds2.build_big();
    for(int i=0; i<m; ++i) cin >> b[i],sp[0][i]=b[i];
    for(int j=1; j<18; ++j){
        for(int i=0; i+(1<<j)<=m; ++i){
            sp[j][i]=__gcd(sp[j-1][i],sp[j-1][i+(1<<(j-1))]);
        }
    }
    while(q--){
        char op; cin >> op;
        if(op=='U'){
            int p,x; cin >> p >> x; p--;
            bit.add(p,-a[p]);
            a[p]=x;
            bit.add(p,a[p]);
            for(int i=1; i<K; ++i) ds[i].set(p,x);
            ds2.set(p,x);
        }
        else{
            int l,r,s,t; cin >> l >> r >> s >> t; l--,r--,s--,t--;
            int g=__gcd(sp_query(s,t),r-l+1);
            ll sum=bit.sum(r)-bit.sum(l-1);
            int tar=mul(sum%mod,Pow(g));
            if(g<K){
                int res=sub(ds[g].sum(r),ds[g].sum(l-1));
                if(res==mul(tar,ds[g].tot)) cout << "Yes\n";
                else cout << "No\n";
            }
            else{
                vector<int> vec;
                int lst=ds2.sum(l-1),res=0;
                for(int i=l-1+g; i<=r; i+=g){
                    int nw=ds2.sum(i);
                    int val=mul(sub(nw,lst),ipw[i-g+1]);
                    res=add(res,val);
                    lst=nw;
                }
                int tmp=mul(sub(1,pw[g]),Pow(sub(1,pw[1])));
                if(res==mul(tar,tmp)) cout << "Yes\n";
                else cout << "No\n";
            }
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    for(int i=0; i<N; ++i) seed[i]=rng()%(mod-5)+4;
    pw[0]=1;
    for(int i=1; i<N; ++i) pw[i]=mul(pw[i-1],seed[0]);
    for(int i=0; i<N; ++i) ipw[i]=Pow(pw[i]);
    int t=1; //cin >> t;
    while(t--) ahcorz();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 23ms
memory: 213124kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 287ms
memory: 219536kb

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: 269ms
memory: 225612kb

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: 264ms
memory: 225340kb

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: 468ms
memory: 225612kb

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 26206th words differ - expected: 'Yes', found: 'No'