QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#252954 | #7627. Phony | Stargazer | TL | 64ms | 65660kb | C++14 | 4.0kb | 2023-11-16 15:46:22 | 2023-11-16 15:46:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define fi first
#define se second
#define pb push_back
#define ll long long
cs int RLEN=1<<20|1;
#define gc getchar
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
template<class tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<class tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=500005;
char xxx;
int n,m,k;
ll a[N];
namespace seg{
cs int M=N*40;
int lc[M],rc[M];
int sz[M],tot;
void insert(int &u,int l,int r,int v){
if(!u)u=++tot;
sz[u]++;
if(l==r){
return;
}
int mid=(l+r)/2;
if(v<=mid)insert(lc[u],l,mid,v);
else insert(rc[u],mid+1,r,v);
}
int find(int u,int l,int r,int k){
if(l==r){
return l;
}
int mid=(l+r)/2;
if(k<=sz[lc[u]])return find(lc[u],l,mid,k);
else return find(rc[u],mid+1,r,k-sz[lc[u]]);
}
void merge(int &r1,int r2,int l,int r){
if(!r1||!r2){r1=r1+r2;return;}
sz[r1]+=sz[r2];
if(l==r)return;
int mid=(l+r)/2;
merge(lc[r1],lc[r2],l,mid);
merge(rc[r1],rc[r2],mid+1,r);
}
void split(int &r1,int &r2,int u,int l,int r,int k){
if(u==0)return;
r1=++tot,r2=++tot;
int mid=(l+r)/2;
if(k==0){
r1=u,r2=0;return;
}
if(l==r&&k<sz[u]){
sz[r2]=k,sz[r1]=sz[u]-k;
return;
}
if(sz[rc[u]]==k){
lc[r1]=lc[u];
rc[r1]=0;
lc[r2]=0;
rc[r2]=rc[u];
}
else if(sz[rc[u]]<k){
rc[r1]=0;
rc[r2]=rc[u];
split(lc[r1],lc[r2],lc[u],l,mid,k-sz[rc[u]]);
}
else if(sz[rc[u]]>k){
lc[r1]=lc[u];
lc[r2]=0;
split(rc[r1],rc[r2],rc[u],mid+1,r,k);
}
sz[r1]=sz[lc[r1]]+sz[rc[r1]];
sz[r2]=sz[lc[r2]]+sz[rc[r2]];
}
}
#define pli pair<ll,int>
char op[5];
char yyy;
int main(){
#ifdef Stargazer
freopen("2.in","r",stdin);
#endif
//cout<<(&yyy-&xxx)/1024/1024<<'\n';
n=read(),m=read(),k=read();
for(int i=1;i<=n;i++)a[i]=readll();
sort(a+1,a+n+1);
vector<pli> rt;
vector<int> sm;
for(int i=1;i<=n;i++){
ll v=a[i]/k;
if(rt.size()&&rt.back().fi==v){
seg::insert(rt.back().se,0,k-1,a[i]%k);
sm.back()++;
}
else{
int x=0;
seg::insert(x,0,k-1,a[i]%k);
rt.pb(pli(v,x));
sm.pb(1);
}
}
for(int i=(int)rt.size()-1;i;i--)sm[i-1]+=sm[i];
for(int tt=1;tt<=m;tt++){
scanf("%s",op);
if(op[0]=='C'){
ll t=readll();
while(t){
if(rt.size()==1){
ll x1=t/n,x2=t%n;
rt.back().fi-=x1;
if(x2==0){
}
else{
int r1=0,r2=0;
seg::split(r1,r2,rt.back().se,0,k-1,x2);
ll x=rt.back().fi;
rt.pop_back();
sm.pop_back();
rt.pb(pli(x-1,r2));
rt.pb(pli(x,r1));
sm.pb(n);
sm.pb(n-x2);
}
t=0;
}
else{
int len=rt.size();
ll del=rt[len-1].fi-rt[len-2].fi;
if(del*sm.back()<=t){
t-=del*sm.back();
seg::merge(rt[len-2].se,rt[len-1].se,0,k-1);
rt.pop_back();
sm.pop_back();
}
else{
ll x1=t/sm.back(),x2=t%sm.back();
rt.back().fi-=x1;
int r1=0,r2=0;
seg::split(r1,r2,rt.back().se,0,k-1,x2);
if(rt[len-2].fi+1==rt[len-1].fi){
seg::merge(rt[len-2].se,r2,0,k-1);
rt[len-1].se=r1;
//sm[len-2]+=x2;
sm[len-1]=sm[len-1]-x2;
}
else{
ll x=rt.back().fi,y=sm.back();
rt.pop_back();
sm.pop_back();
rt.pb(pli(x-1,r2));
rt.pb(pli(x,r1));
sm.pb(y);
sm.pb(y-x2);
}
t=0;
}
}
}
}
else{
int x=read();
int l=0,r=rt.size()-1,res=0;
while(l<=r){
int mid=(l+r)/2;
if(sm[mid]>=x)res=mid,l=mid+1;
else r=mid-1;
}
cout<<rt[res].fi*k+seg::find(rt[res].se,0,k-1,sm[res]-x+1)<<'\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
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: 5732kb
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: 0
Accepted
time: 1ms
memory: 5932kb
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 6114 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:
ok 56 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 5768kb
input:
100 300 3453213 4777243 17293302 43453992 45342348 82151965 11360220 63630258 38237802 1 56066162 75020027 83365329 100659838 2141897 73421986 102600372 100824166 46869742 31931613 26168082 41399743 62249685 31666167 96044265 81576202 44039394 94271661 37319513 46613514 14176026 23991180 3310773 635...
output:
16238806 100824166 74028301 100824166 98702945 100659838 3066866 82151965 78167694 86340309 16238806 64926204 73585978 16238806 64926204 4777243 62249685 78951605 16238806 3066866 77853267 78427881 75980670 43453992 16238806 1 78122989 62404688 72949759 3310773 35761909 44960459 73552383 72045179 16...
result:
ok 159 lines
Test #5:
score: 0
Accepted
time: 8ms
memory: 10644kb
input:
10000 10000 424242 17989609 33305173 36700219 9019831 18836819 21791961 21965035 18824893 1921235 23926509 28110961 33993409 12966853 13082665 4452379 1637119 38371575 1826245 36931693 1 33924345 30310225 30503101 4578015 31263907 15733393 40333897 34523425 25601465 11528899 18236695 4978289 9301153...
output:
29899255 19256287 20728753 27691558 11569357 18782611 6940738 25519453 36411607 15396403 20282701 5151091 13921909 21284225 20657428 13921909 19561543 11116483 30447757 38758135 7394929 27457873 34310557 1419251 40938731 25617811 25928137 21610443 40849627 18524773 24971899 24506287 4463929 27691558...
result:
ok 4977 lines
Test #6:
score: 0
Accepted
time: 8ms
memory: 10420kb
input:
10000 10000 8633427 538078847 573328001 833039873 394897857 557339356 788138551 409068537 418595873 489365441 734786049 510598641 38313681 218800001 757899321 509729089 719587751 396447437 1228081 824921431 557992001 176123501 195314201 316694001 77352241 390252445 488382377 688760625 683480525 7293...
output:
741597921 684643385 244445841 679897197 788928601 972172681 949082401 473000401 79937561 724673651 683480525 854680935 660858076 235090570 532125856 394971761 439375061 765033025 256613601 932699581 712850809 553280433 133989601 529728321 79937561 753982913 438698461 756463614 719635425 653599361 78...
result:
ok 4974 lines
Test #7:
score: 0
Accepted
time: 8ms
memory: 11904kb
input:
10000 10000 234335 38273 570241 147447 980201 158871 620297 217341 747545 477489 864709 74921 933841 364881 763649 637606 388241 559121 571796 710541 375597 791873 796201 310895 217601 120001 347961 16001 719721 23281 502721 669601 42081 532097 525926 794801 841781 892801 487801 899921 847065 228801...
output:
872001 598031 77481 222769 54785 977985 400801 623201 239481 479121 641751 27641 637501 280769 587202 120001 353441 276561 205601 645169 205201 840423 842665 280001 619395 327041 261313 59801 741666 376 901021 633685 338241 815153 598031 547691 802993 832401 442001 280769 569121 434756 841441 735377...
result:
ok 4970 lines
Test #8:
score: 0
Accepted
time: 4ms
memory: 6820kb
input:
9864 10000 233 2321 4497 5656 4866 2321 2296 1173 785 9809 8021 3601 3676 3671 2001 8641 7921 4001 7851 5156 9961 5376 965 8176 5247 5681 3041 1201 1937 699 545 6001 9401 529 8393 9445 1601 961 51 5601 1 5329 4257 8001 2001 3161 2751 5889 6353 2473 6720 1421 4169 7201 1101 9521 9009 5921 5249 8761 7...
output:
5609 5049 8501 9751 6625 2351 6761 9041 2451 8561 6249 3099 4845 4401 3265 9416 9592 8001 9528 6009 9568 4241 8061 7871 2001 821 3793 703 5576 3265 5001 8365 9378 1981 1121 1441 9355 6401 561 3601 8601 5361 8811 4801 5377 3735 769 1496 401 2306 6451 241 8025 8376 6551 8705 3401 1 5281 1531 976 7185 ...
result:
ok 4952 lines
Test #9:
score: 0
Accepted
time: 63ms
memory: 65660kb
input:
500000 4 86 7389249156947561 9098507703019521 3864091904486041 6310459731705571 647583641047201 1621185944707376 7003000429904937 593897105426626 9875992015549861 6557342520948641 9526782645198001 6401373507717121 3893859617993451 4665953390717037 889563644563201 6303536850022463 4409281560689537 43...
output:
9776337802111349 1191089114896223
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 64ms
memory: 59368kb
input:
500000 4 38 6315784043021797 596519996425501 54280272213000001 25297014706267501 381135807724572001 1562706443227627 12734737545675181 48209123950130251 210066342820346881 11997568254816001 1328078731348513 7836814573901041 145542395686987153 35504248422218626 3019601348227201 441053811513439741 227...
output:
927406470830660237 26771400341427457
result:
ok 2 lines
Test #11:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
1000 1000 30 4288386677374751 2662519464063971 4420636922012714 1205174734895841 5180156019151001 2693464561053401 1639891393987585 4195001110670401 6591575153723641 4835655971249743 8713497968125113 4361863383313001 9458730022038216 195078418495057 9840542551744851 4279436254933176 228287227132113 ...
output:
2580641985266797 1324532342145969 699248987828633 1010825796405001 415254197223673 4437530592262803 8698057636492001 3294284903690863 7479153211415601 2533180893181505 7778707561448995 3294284903690863 2562505687756801 3932218574465861 5933603589438393 9714884423972426 6541188010486880 6695513869117...
result:
ok 492 lines
Test #12:
score: 0
Accepted
time: 0ms
memory: 5880kb
input:
1000 1000 20 13488374345924801 43610227415330311 2809367337504001 55479626248453921 46769838945139126 43792160864601601 31136925209007223 50701143722818513 20372262029027761 44373489892234721 45444219805100721 19250473390433001 24306584421061801 6631609709598721 48119896722940561 5506928429719201 61...
output:
49243684713094401 80511583135737601 43868258458230753 24470961950774086 58871193301701481 21244892632911361 61855037591352341 53852795162052481 11687618439170101 99250681772700161 43561491591910701 5353066467314821 1392491209412161 58435920489024396 51571596551244001 19673630481159601 10664493472993...
result:
ok 504 lines
Test #13:
score: -100
Time Limit Exceeded
input:
1000 1000 1000000000000 76723071693841 4001941589666283 4076282713984577 6234887627733381 4897638660755449 2328368250736040 196595968770531 7992824401757137 7795120279050241 2773491889005001 1966967217456876 2364594270616769 1920097794021701 7810375092696225 546469103980101 9613327462804837 31385262...