QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291582#7627. PhonycqbzlyWA 1ms7776kbC++143.0kb2023-12-26 22:36:002023-12-26 22:36:00

Judging History

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

  • [2023-12-26 22:36:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7776kb
  • [2023-12-26 22:36:00]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
const int N=5e5+5;
int n,m,tot;
ll K,a[N],tag;
int cnt;
pair<ll,int>q[N];
string str;
mt19937 gen(114514);
struct node{
    int l,r,fix,sz;
    ll val;
}t[N];
int newnode(ll val){
    tot++;t[tot].fix=gen(),t[tot].sz=1,t[tot].val=val;
    return tot;
}
void pushup(int p){
    t[p].sz=t[t[p].l].sz+t[t[p].r].sz+1;
}
int build(int l,int r){
    if(l>r)return 0;
    int mid=l+r>>1,p=newnode(a[mid]);
    t[p].r=build(l,mid-1),t[p].l=build(mid+1,r);
    pushup(p);return p;
}
int merge(int x,int y){
    if(!x||!y)return x+y;
    if(t[x].fix>t[y].fix){
        t[x].r=merge(t[x].r,y);
        pushup(x);return x;
    }
    else{
        t[y].l=merge(x,t[y].l);
        pushup(y);return y;
    }
}
void split(int rt,int &x,int &y,int val){
    if(!rt){
        x=y=0;
        return;
    }if(t[t[rt].l].sz+1<=val){
        x=rt;
        split(t[x].r,t[x].r,y,val-t[t[x].l].sz-1);
        pushup(x);
    }
    else{
        y=rt;
        split(t[y].l,x,t[y].l,val);
        pushup(y);
    }
}
void split1(int rt,int &x,int &y,ll val){
    if(!rt){
        x=y=0;
        return;
    }
    if(t[rt].val<=val){
        x=rt;
        split1(t[x].r,t[x].r,y,val);
        pushup(x);
    }
    else{
        y=rt;
        split1(t[y].l,x,t[y].l,val);
        pushup(y);
    }
}
int query(int rt,ll val){
    if(!rt)return 0;
    if(val>=t[rt].val)return t[t[rt].l].sz+1+query(t[rt].r,val);
    return query(t[rt].l,val);
}
ll qmax(int rt){
    while(t[rt].r)rt=t[rt].r;
    return t[rt].val;
}
int main(){
    //freopen("data.in","r",stdin);
    //freopen("own.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>m>>K;for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n),reverse(a+1,a+1+n);
    ll cur=0;
    for(int i=1;i<=m;i++){
        cin>>str;ll x;cin>>x;
        if(str[0]=='A')q[++cnt]={cur,n-x+1};
        else cur+=x;
    }
    int it=1,it1=1;while(it+1<=n&&a[1]-a[it+1]<=K)it++;
    cur=0;int rt1=build(1,it),rt2=build(it+1,n);
    while(it1<=cnt){
        ll tmp=(it==n)?inf:(a[it]-a[it+1]+K-1)/K*it;
        while(it1<=cnt&&q[it1].fi<=cur+tmp){
            ll rest=q[it1].fi-cur,val1=rest/it,val2=rest%it;
            int x,y;split(rt1,x,y,it-val2);
            ll l=-1e18,r=1e18,res=0;
            while(l<=r){
                ll mid=l+r>>1;
                if(query(x,mid+(tag+val1)*K)+query(y,mid+(tag+val1+1)*K)+query(rt2,mid)>=q[it1].se)res=mid,r=mid-1;
                else l=mid+1;
            }cout<<res<<"\n";
            it1++;rt1=merge(x,y);
        }
        cur+=tmp,tag+=(a[it]-a[it+1]+K-1)/K;
        ll val=max(qmax(rt1)-tag*K,qmax(rt2));
        while(it+1<=n&&a[it+1]>=val-K){
            it++;int x,y,z;split(rt2,rt2,x,n-it);
            t[x].val+=tag*K;
            split1(rt1,y,z,a[it]+tag*K);
            rt1=merge(merge(y,x),z);
        }
    }
}

詳細信息

Test #1:

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

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: 1ms
memory: 7696kb

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: 7776kb

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
7653
7531
5291
5001
2042
4721
4721
6881
4097
7187
7218
7035
7018
811
6752
2561
6701
6114
6135
3581
5291
1485
5976
5393
2042
5303
5171
5205
4721
5090
4029
4097
4591
4819
4550
4705
2042
4535
4454
4604
4435
3581
4350
115
2042
4284
2042
4274
1485
4335
-17549

result:

wrong answer 6th lines differ - expected: '7647', found: '7653'