QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#253123#7627. PhonyGeospizaWA 2ms9808kbC++143.5kb2023-11-16 18:22:362023-11-16 18:22:36

Judging History

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

  • [2023-11-16 18:22:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9808kb
  • [2023-11-16 18:22:36]
  • 提交

answer

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
#define Ma 1000005
#define G 3
#define N 13
#define pb push_back
#define L (1<<21)
#define ls p<<1
#define rs p<<1|1
#define i128 __int128
using namespace std;
ll n,m,k;
ll a[Ma],pn[Ma];
ll pp[Ma];

struct sgtree{
    struct node{
        ll l,r,w;
    }t[Ma<<2];
    void build(ll p,ll l,ll r)
    {
        t[p].l=l,t[p].r=r,t[p].w=0;
        if (l==r)
            return;
        ll mid=(l+r)>>1;
        build(ls,l,mid),build(rs,mid+1,r);
        return;
    }
    void change(ll p,ll l,ll r)
    {
        if (l<=t[p].l&&t[p].r<=r)
        {
            t[p].w++;
            return;
        }
        ll mid=(t[p].l+t[p].r)>>1;
        if (l<=mid) change(ls,l,r);
        if (r>mid) change(rs,l,r);
        t[p].w=t[ls].w+t[rs].w;
        return;
    }
    ll ask(ll p,ll l,ll r)
    {
        if (l>r)
            return 0;
        if (l<=t[p].l&&t[p].r<=r)
            return t[p].w;
        ll val=0;
        ll mid=(t[p].l+t[p].r)>>1;
        if (l<=mid) val+=ask(ls,l,r);
        if (r>mid) val+=ask(rs,l,r);
        return val;
    }
    ll ask2(ll p,ll x)
    {
        if (t[p].l==t[p].r)
            return t[p].l;
        if (x>=t[ls].w)
            return ask2(rs,x-t[ls].w);
        else
            return ask2(ls,x);
        
    }
}T;


void sol()
{
    cin>>n>>m>>k;
    for (ll i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for (ll i=1;i<=n;i++)
        pn[i]=(a[n]-a[i])/k*k+a[i],pp[i]=pn[i];
    sort(pp+1,pp+n+1);
    ll tot=unique(pp+1,pp+n+1)-(pp+1);
    T.build(1,1,tot);
    i128 ans=0,add=0;
    ll cnt=n-1;
    T.change(1,tot,tot);
    while (m--)
    {
        char op,t;
        ll x;
        cin>>op>>x;
        if (op=='A')
        {
            if (x>n-cnt)
                printf("%lld\n",a[n-x+1]);
            else
            {
                ll all=n-cnt;
                ll pl=(ans+add)/all,pr=(ans+add)%all+x;
                if (pr>all)
                    pl++,pr-=all;
                ll id=T.ask2(1,all-pr);
                printf("%lld\n",pp[id]-pl*k);
            }
        }
        else
        {
            ans+=x;
            while (cnt)
            {
                if (a[cnt]==a[cnt+1])
                {
                    ll l=lower_bound(pp+1,pp+tot+1,pn[cnt])-pp;
                    add+=(pn[cnt]-a[cnt])/k;
                    T.change(1,l,l);
                    cnt--;
                    continue;
                }
                i128 pw=(i128)1*(a[cnt+1]-a[cnt])/k*(n-cnt);
                ll addl=((a[cnt]-a[cnt+1])%k+pn[cnt]);
                ll addr=pn[cnt+1]-1;
                ll l=lower_bound(pp+1,pp+tot+1,pn[cnt])-pp;
                ll pl=lower_bound(pp+1,pp+tot+1,addl)-pp,pr=upper_bound(pp+1,pp+tot+1,addr)-pp-1;
				pw+=T.ask(1,pl,pr);
                addl+=k;
                pl=lower_bound(pp+1,pp+tot+1,addl)-pp;
                pw+=T.ask(1,pl,tot);
                if (pw>=ans)
                    break;
                ans-=pw,add+=pw;
                add+=(pn[cnt]-a[cnt])/k;
                
                T.change(1,l,l);
                cnt--;
            }
            //printf("cnt=%lld\n",cnt);
        }
    }
}


int	main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int tt=1;
    //cin>>tt;
    while (tt--)
        sol();
    return 0;
}
/*
3 20 1
1 4 7
C 1
A 1
A 2
A 3
C 3
A 1
A 2
A 3
C 100
A 1
A 2
A 3
*/

詳細信息

Test #1:

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

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: 2ms
memory: 9800kb

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: 2ms
memory: 9808kb

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
7187
7218
7035
7018
811
6752
2561
6683
6103
6135
3581
5291
1485
5957
5393
2042
5303
5171
5205
4721
5084
4029
4097
4586
4816
4721
4698
2042
4535
4454
4603
4422
3581
4345
115
2042
4274
2042
4273
1485
4326
-17552

result:

wrong answer 23rd lines differ - expected: '6114', found: '6103'