QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253099#7627. PhonyGeospizaWA 1ms9968kbC++203.3kb2023-11-16 17:52:012023-11-16 17:52:02

Judging History

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

  • [2023-11-16 17:52:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9968kb
  • [2023-11-16 17:52:01]
  • 提交

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 l=lower_bound(pp+1,pp+tot+1,((a[cnt]-a[cnt+1])%k+pn[cnt]+k))-pp;
				pw+=T.ask(1,l,tot);
                if (pw>=ans)
                    break;
                ans-=pw,add+=pw;
                add+=(pn[cnt]-a[cnt])/k;
                l=lower_bound(pp+1,pp+tot+1,pn[cnt])-pp;
                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 5 5
 7 3 9
 A 3
 C 1
 A 2
 C 2
 A 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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
7988
2945
7434
7323
5291
5001
2042
4721
4721
6656
4097
6785
6795
6686
6538
811
6368
2561
6235
5882
5886
3581
5693
1485
5724
5143
2042
5057
4961
4993
4815
4871
4535
4535
4461
4635
4455
4535
2042
4330
4251
4370
4235
4020
4172
115
2042
4137
2042
4127
1485
4027
-17552

result:

wrong answer 4th lines differ - expected: '8200', found: '7988'