QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253081 | #7627. Phony | Geospiza# | WA | 2ms | 9832kb | C++20 | 2.9kb | 2023-11-16 17:25:32 | 2023-11-16 17:25:34 |
Judging History
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)
{
i128 pw=(i128)1*((a[n]-a[cnt])/k-(a[n]-a[cnt+1])/k)*(n-cnt);
ll l=lower_bound(pp+1,pp+tot+1,pn[cnt])-pp;
pw-=T.ask(1,1,l);
pw=max(pw,(i128)0);
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 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: 9716kb
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: 9832kb
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: 9756kb
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 8012 2945 7493 7400 5291 5001 2042 4721 4721 6656 4097 6785 6795 6686 6683 811 6336 2561 6235 5672 5587 5370 5425 1485 5472 5058 2042 4996 4921 4950 4760 4728 4454 4455 4189 4343 4179 4262 4123 4085 4018 4123 4006 3803 3940 115 3757 3911 3757 3906 3745 3904 -17552
result:
wrong answer 4th lines differ - expected: '8200', found: '8012'