QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#275816 | #7627. Phony | Yu_Jie | WA | 5ms | 28284kb | C++14 | 2.9kb | 2023-12-05 08:36:11 | 2023-12-05 08:36:12 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef __int128 LL;
using namespace std;
const int N=500005;
int n,m,row,col,b[N],c[N];
ll a[N],k,mpr[N],mpc[N];
LL tim[N],ctm;
vector<int> vc[N];
struct sgt {
int sum[4*N];
void modify(int x,int p=1,int l=1,int r=col) {
if(l==r) {sum[p]++; return ;}
int mid=l+r>>1;
if(x<=mid) modify(x,p<<1,l,mid);
else modify(x,p<<1|1,mid+1,r);
sum[p]=sum[p<<1]+sum[p<<1|1];
}
int binary(int v,int p=1,int l=1,int r=col) {
if(l==r) return l;
int mid=l+r>>1;
if(sum[p<<1|1]<v) return binary(v-sum[p<<1|1],p<<1,l,mid);
return binary(v,p<<1|1,mid+1,r);
}
} tr;
ll read() {
ll x=0; char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='C'||c=='A') return c=='C';
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
return x;
}
int main() {
n=read(); m=read(); k=read();
for(int i=1;i<=n;i++) a[i]=read();
sort(a+1,a+n+1,[](ll x,ll y){return x>y;});
for(int i=1;i<=n;i++) mpr[i]=a[i]/k;
sort(mpr+1,mpr+n+1); row=unique(mpr+1,mpr+n+1)-mpr-1;
for(int i=1;i<=n;i++) b[i]=lower_bound(mpr+1,mpr+row+1,a[i]/k)-mpr;
for(int i=1;i<=n;i++) mpc[i]=a[i]%k;
sort(mpc+1,mpc+n+1); col=unique(mpc+1,mpc+n+1)-mpc-1;
for(int i=1;i<=n;i++) c[i]=lower_bound(mpc+1,mpc+col+1,a[i]%k)-mpc;
for(int i=1;i<=n;i++) vc[b[i]].push_back(c[i]);
for(int i=row,j=0;i>=1;j+=vc[i].size(),i--) {
sort(vc[i].begin(),vc[i].end());
tim[i]=tim[i+1]+(LL)j*(mpr[i+1]-mpr[i]);
}
for(int i:vc[row]) tr.modify(i);
for(int i=row,sz=vc[row].size(),re=0;m--;) {
if(read()) {
ll x=read();
ctm+=x;
for(;i>1&&ctm>=tim[i-1];i--) {
re=0;
for(int j:vc[i-1]) tr.modify(j),sz++;
}
if(i>1&&ctm-tim[i]>(tim[i-1]-tim[i]-1)*sz) {
if(!re) {
re=sz;
x=ctm-tim[i]-(tim[i-1]-tim[i]-1)*sz;
}
re-=x;
int y=tr.binary(sz-re);
while(vc[i-1].size()&&vc[i-1].back()>=y) {
sz++; tr.modify(vc[i-1].back());
vc[i-1].pop_back();
}
}
}
else {
int x=read();
if(x>sz) {printf("%lld\n",a[x]); continue;}
ll ans;
if(!re) {
if(x<=sz-(ctm-tim[i])%sz) ans=(mpr[i]-(ctm-tim[i])/sz)*k+mpc[tr.binary((ctm-tim[i])%sz+x)];
else ans=(mpr[i]-(ctm-tim[i]+sz-1)/sz)*k+mpc[tr.binary(((ctm-tim[i])%sz+x-1)%sz+1)];
}
else {
if(x<=re) ans=(mpr[i-1]+1)*k+mpc[tr.binary(sz-re+x)];
else ans=(mpr[i-1])*k+mpc[tr.binary(x-re)];
}
printf("%lld\n",ans);
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 28256kb
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: 5ms
memory: 28284kb
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: 0ms
memory: 26208kb
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 4591 4816 4586 4705 2042 4535 4454 4603 4435 3581 4345 115 2042 4284 2042 4274 1485 4326 -17552
result:
wrong answer 23rd lines differ - expected: '6114', found: '6103'