QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350470 | #7627. Phony | hl666 | WA | 6ms | 15896kb | C++17 | 4.4kb | 2024-03-10 19:09:50 | 2024-03-10 19:09:53 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cctype>
#include<vector>
#include<algorithm>
#define int long long
#define RI register int
#define CI const int&
using namespace std;
const int N=500005;
#define Tp template <typename T>
class FileInputOutput
{
private:
static const int S=1<<21;
#define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
#define pc(ch) (Ftop!=Fend?*Ftop++=ch:(fwrite(Fout,1,S,stdout),*(Ftop=Fout)++=ch))
char Fin[S],Fout[S],*A,*B,*Ftop,*Fend; int pt[30];
public:
inline FileInputOutput(void) { Ftop=Fout; Fend=Fout+S; }
Tp inline void read(T& x)
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
}
inline void get_char(char& ch)
{
while (!isalpha(ch=tc()));
}
Tp inline void write(T x,const char ch='\n')
{
if (x<0) x=-x,pc('-');
RI ptop=0; while (pt[++ptop]=x%10,x/=10);
while (ptop) pc(pt[ptop--]+48); pc(ch);
}
inline void flush(void)
{
fwrite(Fout,1,Ftop-Fout,stdout);
}
#undef tc
#undef pc
}F;
int n,m,k,a[N],x,rt[N],sz[N],idx; vector <int> rst,module;
class Segment_Tree
{
private:
struct segment
{
int ch[2],sz;
}O[N*20];
public:
inline void insert(int& x,CI pos,CI l=0,CI r=module.size()-1)
{
if (!x) x=++idx; ++O[x].sz; if (l==r) return; int mid=l+r>>1;
if (pos<=mid) insert(O[x].ch[0],pos,l,mid); else insert(O[x].ch[1],pos,mid+1,r);
}
inline int merge(int x,int y,CI l=0,CI r=module.size()-1)
{
if (!x||!y) return x|y; if (l==r) return O[x].sz+=O[y].sz,x; int mid=l+r>>1;
O[x].ch[0]=merge(O[x].ch[0],O[y].ch[0],l,mid);
O[x].ch[1]=merge(O[x].ch[1],O[y].ch[1],mid+1,r);
O[x].sz=O[O[x].ch[0]].sz+O[O[x].ch[1]].sz; return x;
}
inline int find_kth(CI x,CI rk,CI l=0,CI r=module.size()-1)
{
if (l==r) return module[l]; int mid=l+r>>1;
if (rk<=O[O[x].ch[1]].sz) return find_kth(O[x].ch[1],rk,mid+1,r);
return find_kth(O[x].ch[0],rk-O[O[x].ch[1]].sz,l,mid);
}
inline int query(CI x,CI lim,CI grt,CI l=0,CI r=module.size()-1)
{
if (!lim||module[r]<=grt) return 0; if (grt<module[l]) return O[x].sz; int mid=l+r>>1;
if (lim<=O[O[x].ch[1]].sz) return query(O[x].ch[1],lim,grt,mid+1,r);
return query(O[x].ch[1],O[O[x].ch[1]].sz,grt,mid+1,r)+query(O[x].ch[0],lim-O[O[x].ch[1]].sz,grt,l,mid);
}
}SEG;
signed main()
{
//freopen("I.in","r",stdin); freopen("I.out","w",stdout);
RI i; for (F.read(n),F.read(m),F.read(k),i=1;i<=n;++i)
F.read(a[i]),rst.push_back(a[i]/k),module.push_back(a[i]%k);
sort(rst.begin(),rst.end()); rst.erase(unique(rst.begin(),rst.end()),rst.end());
sort(module.begin(),module.end()); module.erase(unique(module.begin(),module.end()),module.end());
for (i=1;i<=n;++i)
{
int id=lower_bound(rst.begin(),rst.end(),a[i]/k)-rst.begin(); ++sz[id];
SEG.insert(rt[id],lower_bound(module.begin(),module.end(),a[i]%k)-module.begin());
}
vector <int> pfx(rst.size()); pfx[0]=sz[0];
for (i=1;i<rst.size();++i) pfx[i]=pfx[i-1]+sz[i];
int pos=0,id=rst.size()-1; for (i=1;i<=m;++i)
{
char opt; F.get_char(opt); F.read(x);
if (opt=='C')
{
while (x>0)
{
if (pos+x<sz[id]) { pos+=x; x=0; break; }
x-=sz[id]-pos; --rst[id]; pos=0;
if (id>0)
{
int steps=(rst[id]-rst[id-1])*sz[id];
if (steps<=x)
{
x-=steps; pfx[id-1]+=sz[id]; sz[id-1]+=sz[id];
rt[id-1]=SEG.merge(rt[id-1],rt[id]); --id;
} else
{
rst[id]-=x/sz[id]; pos=x%sz[id]; x=0;
}
} else
{
rst[0]-=x/n; pos=x%n; x=0;
}
}
} else
{
if (x<=sz[id]-pos)
{
F.write(rst[id]*k+SEG.find_kth(rt[id],pos+x)); continue;
} else x-=(sz[id]-pos);
if (id>0&&rst[id]-1==rst[id-1]&&x<=pos+sz[id-1])
{
int l=0,r=k-1,mid,ret;
while (l<=r)
{
mid=l+r>>1;
if (SEG.query(rt[id],pos,mid)+SEG.query(rt[id-1],sz[id-1],mid)<x) ret=mid,r=mid-1; else l=mid+1;
}
F.write(rst[id-1]*k+ret); continue;
}
if (x<=pos)
{
F.write((rst[id]-1)*k+SEG.find_kth(rt[id],x)); continue;
} else x-=pos;
int l=0,r=id-1,mid,ret;
while (l<=r)
{
mid=l+r>>1;
if (pfx[id-1]-pfx[mid]<x) ret=mid,r=mid-1; else l=mid+1;
}
F.write(rst[ret]*k+SEG.find_kth(rt[ret],x-(pfx[id-1]-pfx[ret])));
}
}
return F.flush(),0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11740kb
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: 0
Accepted
time: 0ms
memory: 11720kb
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: 2ms
memory: 11812kb
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: -100
Wrong Answer
time: 6ms
memory: 15896kb
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:
wrong answer 122nd lines differ - expected: '39112081', found: '39266017'