QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252245#7627. PhonyfAKeZero#WA 1ms3828kbC++174.0kb2023-11-15 17:08:312023-11-15 17:08:31

Judging History

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

  • [2023-11-15 17:08:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2023-11-15 17:08:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline long long read(){
    int w=0;long long x=0;char c=getchar();
    while(!isdigit(c)) w|=c=='-',c=getchar();
    while(isdigit(c)) x=x*10+c-'0',c=getchar();
    return w?-x:x;
}
namespace star
{
    const int maxn=5e5+10;
    inline char gc(){
        char c=getchar();
        while(isspace(c)) c=getchar();
        return c;
    }
    int n,m;
    long long k,a[maxn];
    #define ls son[ro][0]
    #define rs son[ro][1]
    int son[maxn][2],siz[maxn],tot,rnd[maxn],rt1,rt2;
    long long val[maxn];
    inline int newnode(long long a){
        val[++tot]=a,siz[tot]=1,rnd[tot]=rand();return tot;
    }
    inline void pushup(const int &ro){
        siz[ro]=siz[ls]+siz[rs]+1;
    }
    int merge(int a,int b){
        if(!a or !b) return a|b;
        if(rnd[a]<rnd[b]){
            son[a][1]=merge(son[a][1],b);
            pushup(a);return a;
        }else{
            son[b][0]=merge(a,son[b][0]);
            pushup(b);return b;
        }
    }
    void split(int ro,long long k,int &a,int &b){
        if(!ro) return a=b=0,void();
        if(val[ro]<=k) a=ro,split(rs,k,rs,b);
        else b=ro,split(ls,k,a,ls);
        pushup(ro);
    }
    inline void insert(int& rt,long long a){
        int x,y;
        split(rt,a,x,y);
        rt=merge(merge(x,newnode(a)),y);
    }
    void splitsz(int ro,int k,int &a,int &b){
        if(!ro) return a=b=0,void();
        if(siz[ls]+1<=k) a=ro,splitsz(rs,k-siz[ls]-1,rs,b);
        else b=ro,splitsz(ls,k,a,ls);
        pushup(ro);
    }
    inline void del(int &rt,int a){
        int x,y,z;
        split(rt,a,x,z);
        split(x,a-1,x,y);
        y=merge(son[y][0],son[y][1]);
        rt=merge(merge(x,y),z);
    }
    inline long long kth(int ro,int a){
        while(true){
            // std::cerr << val[ro] << " ? " << std::endl;
            if(a<=siz[ls]) ro=ls;
            else{
                a-=siz[ls];
                if(--a==0) return val[ro];
                ro=rs;
            }
        }
    }
    #undef ls
    #undef rs
    vector<long long> hold;
    inline void work(){
        n=read(),m=read(),k=read();
        for(int i=1;i<=n;i++) a[i]=read();
        sort(a+1,a+1+n);
        long long h=a[n]/k,i=n;
        while(i and a[i]/k==h){
            h=a[i]/k;
            insert(rt1,a[i]%k);
            i--;
        }
        while(m--){
            // cerr<<"Before:"<<h<<' '<<siz[rt1]<<' '<<siz[rt2]<<endl;
            if(gc()=='C'){
            long long t=read();
            if(t>=siz[rt1]){
                t-=siz[rt1];
                for(auto x:hold) del(rt2,x);
                rt1=merge(rt1,rt2);
                for(auto x:hold) insert(rt1,x);
                hold.clear();
                rt2=0;
                h--;
            }
            while(i and a[i]/k>=h-t/siz[rt1]){
                t-=(h-a[i]/k)*siz[rt1];
                h=a[i]/k;
                insert(rt1,a[i]%k);
                i--;
            }
            h-=t/siz[rt1];
            t-=(t/siz[rt1])*siz[rt1];
            if(t){
                int c;
                splitsz(rt1,siz[rt1]-t,rt1,c);
                rt2=merge(c,rt2);
                t=0;
                // cerr<<"rt2:"<<siz[rt1]<<' '<<siz[rt2]<<' '<<val[rt2]<<endl;
                while(i and a[i]/k>=h-1){
                    hold.push_back(a[i] % k);
                    insert(rt2,a[i]%k);
                    i--;
                }
            }
        }else{
            int x=read();
            if(x>siz[rt1]+siz[rt2]){
                printf("%lld\n",a[n-x+1]);
            }else if(x>siz[rt1]){
                // cerr<<"AAAAAAA:"<<h<<' '<<siz[rt1]<<' '<<siz[rt2]-(x-siz[rt1])+1<<endl;
                printf("%lld\n",k*(h-1)+kth(rt2,siz[rt2]-(x-siz[rt1])+1));
            }else printf("%lld\n",k*h+kth(rt1,siz[rt1]-x+1));
        }
            // cerr<<"After:"<<h<<' '<<siz[rt1]<<' '<<siz[rt2]<<endl<<endl;
        }
    }
}
signed main(){
    star::work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3496kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

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

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3828kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8200
2945
7647
7531
5291
5001
2042
4721
4721
6881
4097
7201
7239
7046
7035
811
6785
2561
6721
6161
6246
3581
5291
1485
6072
5515
2042
5439
5328
5387
5160
5277
4904
4921
4701
5044
4847
4927
2042
4837
4717
4721
4697
4483
4589
115
2042
4438
2042
4614
1485
4624
-14199

result:

wrong answer 15th lines differ - expected: '7187', found: '7201'