QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253271 | #7627. Phony | triccsr | RE | 1ms | 12264kb | C++20 | 3.4kb | 2023-11-16 20:35:16 | 2023-11-16 20:35:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e5+11;
int n,m;
LL k;
LL a[N];
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define mid ((l+r)>>1)
int sum[N<<2];
void push_up(int now){
sum[now]=sum[ls(now)]+sum[rs(now)];
}
void insert(int l,int r,int now,int index,int cnt){
if(l==r){
sum[now]+=cnt;
return;
}
if(index<=mid){
insert(l,mid,ls(now),index,cnt);
}
else{
insert(mid+1,r,rs(now),index,cnt);
}
push_up(now);
}
int interval_sum(int l,int r,int now,int st,int en){
if(st<=l&&r<=en){
return sum[now];
}
int ret=0;
if(st<=mid){
ret+=interval_sum(l,mid,ls(now),st,en);
}
if(en>mid){
ret+=interval_sum(mid+1,r,rs(now),st,en);
}
return ret;
}
pair<int,int> get_kth(int l,int r,int now,int st,int en,int k){
if(l==r){
if(k<=sum[now])
return make_pair(l,k);
return make_pair(-1,sum[now]);
}
if(st<=l&&r<=en){
if(sum[now]<k){
return make_pair(-1,sum[now]);
}
if(sum[rs(now)]>=k){
return get_kth(mid+1,r,rs(now),st,en,k);
}
return get_kth(l,mid,ls(now),st,en,k-sum[rs(now)]);
}
pair<int,int>p=make_pair(-1,sum[now]);
if(en>mid){
p=get_kth(mid+1,r,rs(now),st,en,k);
}
if(p.first==-1&&st<=mid){
p=get_kth(l,mid,ls(now),st,en,k-p.second);
}
return p;
}
#undef ls
#undef rs
#undef mid
map<LL,int> mp;
LL inv[N];
namespace BF{
LL a[N];
void C(LL t){
while(t--){
int index=1;
for(int i=2;i<=n;++i){
if(a[i]>a[index]){
index=i;
}
}
a[index]-=k;
}
}
LL A(LL x){
static LL b[N];
for(int i=1;i<=n;++i)b[i]=a[i];
sort(b+1,b+n+1);
return b[n-x+1];
}
}
int main(){
scanf("%d%d%lld",&n,&m,&k);
set<LL> remSet;
for(int i=1;i<=n;++i){
scanf("%lld",&a[i]);
BF::a[i]=a[i];
remSet.insert(a[i]%k);
}
int rTail=0;
for(LL r:remSet){
++rTail;
mp[r]=rTail;
inv[rTail]=r;
}
sort(a+1,a+n+1);
int setSize=1;
int aTail=n-1;
insert(1,rTail,1,mp[a[n]%k],1);
LL p=a[n]/k;
int front=0;
while(m--){
char s[10];
scanf("%s",s);
if(s[0]=='C'){
LL t;
scanf("%lld",&t);
BF::C(t);
while(aTail>=1){
if((__int128_t)p*setSize+front-(__int128_t)a[aTail]/k*setSize<=(__int128_t)t){
t-=(__int128_t)p*setSize+front-(__int128_t)a[aTail]/k*setSize;
front=0;
p=a[aTail]/k;
insert(1,rTail,1,mp[a[aTail]%k],1);
--aTail;
++setSize;
}
else{
break;
}
}
__int128_t pot=(__int128_t)p*setSize+front-t;
front=(pot%setSize+setSize)%setSize;
p=(pot-front)/setSize;
}
else{
int x;
scanf("%d",&x);
LL ans=-1;
if(x>setSize){
ans=a[aTail-x+setSize+1];
}
else{
LL r=-1;
if(front>=x){
pair<int,int> tmp=get_kth(1,rTail,1,1,rTail,setSize-front+x);
r=inv[tmp.first];
ans=(p+1)*k+r;
}
else{
pair<int,int> tmp=get_kth(1,rTail,1,1,rTail,x-front);
r=inv[tmp.first];
ans=p*k+r;
}
}
LL jury=BF::A(x);
if(jury!=ans){
printf("WA:jury=%lld, ans=%lld\n",jury,ans);
assert(0);
}
printf("%lld\n",ans);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 12264kb
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: 11956kb
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
Runtime Error
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...