QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311684#1831. BruteforceCrayonIsGayWA 3ms62356kbC++147.7kb2024-01-22 17:18:462024-01-22 17:18:46

Judging History

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

  • [2024-01-22 17:18:46]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:62356kb
  • [2024-01-22 17:18:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
const ll N = 1e5+20;
const ll INF = (ll)1e18;
const ll MOD = 998244353;
inline ll read(){
    ll ret=0,f=1;char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') f*=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        ret=(ret<<3)+(ret<<1)+ch-'0';
        ch=getchar();
    }
    return ret*f;
}
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
ll chkpow[10][10];
ll kpow(ll a,ll b,ll mod){
    ll ret=1,base=a%mod;while(b){if(b&1) ret=ret*base%mod;base=base*base%mod;b>>=1;}return ret;
}
inline ll upd(ll x){return (x%MOD+MOD)%MOD;}
ll C[10][10];
inline ll get_d(ll k,ll c,ll w){
    return C[k][c]*kpow(w,k-c,MOD);
}
ll n,m,k,W,a[N];
const ll V = 1e5;
struct segment_tree0{
    ll mod;
    int cnt[N*4],sum[N*4],sum_k[6][N*4];
    int tg[N*4];
    segment_tree0(){memset(cnt,0,sizeof(cnt));memset(sum,0,sizeof(sum));memset(sum_k,0,sizeof(sum_k));memset(tg,0,sizeof(tg));}
    inline void push_up(int rt){
        sum[rt]=sum[rt<<1]+sum[rt<<1|1];
        for(int i=0;i<=k;++i)
            sum_k[i][rt]=upd(sum_k[i][rt<<1]+sum_k[i][rt<<1|1]);
        cnt[rt]=cnt[rt<<1]+cnt[rt<<1|1];
    }
    inline void modify(int rt,int v){
        tg[rt]+=v;
        for(int i=k;i>=0;i--)
            for(int j=i-1;j>=0;j--)
                sum_k[i][rt]=upd(sum_k[i][rt]+1ll*sum_k[j][rt]*get_d(i,j,v));
        sum[rt]=sum_k[k][rt];
    }
    inline void push_down(int rt){
        if(tg[rt]!=0){
            modify(rt<<1,tg[rt]);
            modify(rt<<1|1,tg[rt]);
            tg[rt]=0;
        }
    }
    inline int query_sz(int rt,int l,int r,int idx){
        if(r<=idx) return cnt[rt];
        if(l>idx)  return 0;
        int mid=(l+r)>>1;
        return query_sz(rt<<1,l,mid,idx)+query_sz(rt<<1|1,mid+1,r,idx);
    }
    inline void update_v(int rt,int l,int r,int w,int c){
        if(r<w||l>w) return;
        if(l==r){
            if(c==1){
                ll id=query_sz(1,0,V,w)+1;
                cnt[rt]++;
                // cout<<"id="<<id<<endl;
                for(ll i=0;i<=k;++i)
                    sum_k[i][rt]=upd(1ll*sum_k[i][rt]+1ll*w*kpow(id,i,mod)%mod);
            }else{
                ll id=query_sz(1,0,V,w);
                cnt[rt]--;
                for(ll i=0;i<=k;++i)
                    sum_k[i][rt]=upd(1ll*sum_k[i][rt]-1ll*w*kpow(id,i,mod)%mod);
            }
            sum[rt]=sum_k[k][rt];
            return ;
        }
        int mid=l+r>>1;
        push_down(rt);
        update_v(rt<<1,l,mid,w,c);
        update_v(rt<<1|1,mid+1,r,w,c);
        push_up(rt);
    }
    inline void update_i(int rt,int l,int r,int ql,int qr,int v){
        if(r<ql||l>qr) return;
        if(ql<=l&&r<=qr){
            if(v==1){
                // cout<<"l="<<l<<" r="<<r<<" ql="<<ql<<" qr="<<qr<<" ans=";
                for(int i=k;i>=0;i--)
                    for(int j=i-1;j>=0;j--)
                        sum_k[i][rt]=upd(1ll*sum_k[i][rt]+sum_k[j][rt]*get_d(i,j,v));
            }else{
                for(int i=k;i>=0;i--)
                    for(int j=i-1;j>=0;j--)
                        sum_k[i][rt]=upd(1ll*sum_k[i][rt]+sum_k[j][rt]*get_d(i,j,v));
            }
            // cout<<sum[rt]<<endl;
            sum[rt]=sum_k[k][rt];
            tg[rt]+=v;
            return ;
        }
        int mid=(l+r)>>1;
        push_down(rt);
        update_i(rt<<1,l,mid,ql,qr,v);
        update_i(rt<<1|1,mid+1,r,ql,qr,v);
        push_up(rt);
    }
}sg0;
struct segment_tree1{
    int cnt[N*4],sum[N*4],sum_k[5][5][N*4];
    //                         bi i
    int tg[N*4];
    segment_tree1(){memset(cnt,0,sizeof(cnt));memset(sum,0,sizeof(sum));memset(sum_k,0,sizeof(sum_k));memset(tg,0,sizeof(tg));}
    inline void push_up(int rt){
        sum[rt]=sum[rt<<1]+sum[rt<<1|1];
        for(int i=0;i<W;++i)
            for(int j=0;j<W;++j)
                sum_k[i][j][rt]=upd(sum_k[i][j][rt<<1]+sum_k[i][j][rt<<1|1]);
        cnt[rt]=cnt[rt<<1]+cnt[rt<<1|1];
    }
    inline void modify(int rt,int v){
        v=(v%W+W)%W;
        ll ret[5][5];
        sum[rt]=0;
        for(int j=0;j<W;++j){
            for(int i=0;i<W;++i)
                ret[j][i]=sum_k[j][(i-v+W*2)%W][rt];
            for(int i=0;i<W;++i)
                sum_k[j][i][rt]=ret[j][i];
            for(int i=0;i<W;++i)
                sum[rt]=upd(sum[rt]+1ll*j*kpow(i,k,W)%W*sum_k[j][i][rt]%MOD);
        }
    }
    inline void push_down(int rt){
        if(tg[rt]!=0){
            modify(rt<<1,tg[rt]);
            modify(rt<<1|1,tg[rt]);
            tg[rt<<1]+=tg[rt];tg[rt<<1|1]+=tg[rt];
            tg[rt]=0;
        }
    }
    inline ll query_sz(int rt,int l,int r,int idx){
        if(r<=idx) return cnt[rt];
        if(l>idx)  return 0;
        int mid=(l+r)>>1;
        return query_sz(rt<<1,l,mid,idx)+query_sz(rt<<1|1,mid+1,r,idx);
    }
    inline void update_v(int rt,int l,int r,int w,int c){
        if(r<w||l>w) return;
        if(l==r){
            if(c==1){
                ll id=query_sz(1,0,V,w)+1;
                cnt[rt]++;
                // cout<<"id="<<id<<endl;
                sum_k[w%W][id%W][rt]=upd(sum_k[w%W][id%W][rt]+1);
            }else{
                ll id=query_sz(1,0,V,w);
                cnt[rt]--;
                sum_k[w%W][id%W][rt]=upd(sum_k[w%W][id%W][rt]-1);
            }
            sum[rt]=0;
            for(int j=0;j<W;++j)
                for(int i=0;i<W;++i)
                    sum[rt]=upd(sum[rt]+1ll*j*kpow(i,k,W)%W*sum_k[j][i][rt]%MOD);
            return ;
        }
        int mid=l+r>>1;
        push_down(rt);
        update_v(rt<<1,l,mid,w,c);
        update_v(rt<<1|1,mid+1,r,w,c);
        push_up(rt);
    }
    inline void update_i(int rt,int l,int r,int ql,int qr,int v){
        if(r<ql||l>qr) return;
        if(ql<=l&&r<=qr){
            modify(rt,v);
            tg[rt]+=v;
            return ;
        }
        int mid=(l+r)>>1;
        push_down(rt);
        update_i(rt<<1,l,mid,ql,qr,v);
        update_i(rt<<1|1,mid+1,r,ql,qr,v);
        push_up(rt);
    }
}sg1;
void multi_test(){
    for(int i=0;i<=5;++i){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<=i;++j)
            C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    n=read(),k=read(),W=read();
    sg0.mod=998244353;//sg1.mod=W;
    for(int i=1;i<=n;++i){
        a[i]=read();
        sg0.update_v(1,0,V,a[i],1);
        sg0.update_i(1,0,V,a[i]+1,V,1);
        sg1.update_v(1,0,V,a[i],1);
        sg1.update_i(1,0,V,a[i]+1,V,1);
    }
    ll q=read();
    while(q--){
        ll pos=read(),x=read();
        sg0.update_v(1,0,V,a[pos],-1);
        sg0.update_i(1,0,V,a[pos]+1,V,-1);
        sg0.update_v(1,0,V,x,1);
        sg0.update_i(1,0,V,x+1,V,1);
        // cout<<"*"<<sg0.sum[1]<<endl;
        sg1.update_v(1,0,V,a[pos],-1);
        sg1.update_i(1,0,V,a[pos]+1,V,-1);
        sg1.update_v(1,0,V,x,1);
        sg1.update_i(1,0,V,x+1,V,1);
        // cout<<"&"<<sg1.sum[1]<<endl;
        printf("%lld\n",1ll*upd(sg0.sum[1]-sg1.sum[1])*kpow(W,MOD-2,MOD)%MOD);
        a[pos]=x;
    }
    return ;
}
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. fileio in some oi-contest
8. module on time 
9. the number of a same divisor in a math problem
10. multi-information and queries 
*/
signed main(){
    ll T=1;
    while(T--) multi_test();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 61696kb

input:

3 1 1
2 2 8
2
2 5
3 6

output:

36
30

result:

ok 2 number(s): "36 30"

Test #2:

score: 0
Accepted
time: 3ms
memory: 62356kb

input:

4 2 2
1 3 3 7
4
1 1
2 4
3 8
4 8

output:

75
80
103
108

result:

ok 4 number(s): "75 80 103 108"

Test #3:

score: 0
Accepted
time: 0ms
memory: 62172kb

input:

10 1 1
16251 28898 58179 69362 48663 81443 34949 87167 16552 58931
10
6 89124
8 27159
4 7332
1 15852
9 67405
7 19413
10 97472
7 31114
6 31847
5 43794

output:

3511390
3107346
2780002
2779204
3079414
3018965
3365708
3406982
2970195
2936112

result:

ok 10 numbers

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 61704kb

input:

100 2 2
44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...

output:

81216962
1851173
5552645
163221145
142604037
27887681
939434952
51213375
181562234
49675403
62038325
808140891
247600647
150323049
120339986
261885869
261690216
247578015
86003348
140976389
142751076
273424045
402413699
300515771
300819876
193300161
240429411
392633865
361623113
355154190
172731294
...

result:

wrong answer 2nd numbers differ - expected: '152846115', found: '1851173'