QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#859415 | #8704. 排队 | Meatherm | 0 | 299ms | 9012kb | C++14 | 2.5kb | 2025-01-17 18:49:00 | 2025-01-17 18:49:09 |
Judging History
answer
# include <bits/stdc++.h>
const int N=300010,INF=0x3f3f3f3f;
inline int read(void){
int res,f=1;
char c;
while((c=getchar())<'0'||c>'9')
if(c=='-') f=-1;
res=c-48;
while((c=getchar())>='0'&&c<='9')
res=res*10+c-48;
return res*f;
}
std::mt19937 rng(114514);
struct Node{
int val,lc,rc,rnd,siz,fa,mx;
}tr[N];
int cnt;
inline int& lc(int x){
return tr[x].lc;
}
inline int& rc(int x){
return tr[x].rc;
}
inline void node(int &x,int val){
return x=++cnt,tr[x]=(Node){val,0,0,(int)rng(),1,0,val},void();
}
inline void psup(int x){
tr[x].siz=tr[lc(x)].siz+tr[rc(x)].siz+1;
tr[x].mx=std::min({tr[lc(x)].mx,tr[rc(x)].mx,tr[x].val});
if(lc(x)) tr[lc(x)].fa=x;
if(rc(x)) tr[rc(x)].fa=x;
return;
}
void merge(int &cur,int u,int v){
if(!u||!v) return cur=u|v,void();
tr[u].fa=tr[v].fa=0; // ???
if(tr[u].rnd<tr[v].rnd) cur=u,merge(rc(cur),rc(u),v);
else cur=v,merge(lc(cur),u,lc(v));
psup(cur);
return;
}
void split(int cur,int &u,int &v,int k){
if(!cur) return u=v=0,void();
tr[cur].fa=0;
if(tr[lc(cur)].siz+1<=k) u=cur,split(rc(cur),rc(u),v,k-tr[lc(cur)].siz-1),psup(u);
else v=cur,split(lc(cur),u,lc(v),k),psup(v);
return;
}
inline int getrk(int x){
int ans=1+tr[lc(x)].siz;
while(tr[x].fa) ans+=(tr[lc(tr[x].fa)].siz+1)*(x!=lc(tr[x].fa)),x=tr[x].fa;
return ans;
}
void splitv(int cur,int &u,int &v,int k){
if(!cur) return u=v=0,void();
tr[cur].fa=0;
if(std::min(tr[lc(cur)].mx,tr[cur].val)>=k) u=cur,split(rc(cur),rc(u),v,k),psup(u);
else v=cur,splitv(lc(cur),u,lc(v),k),psup(v);
}
int n,T,rt;
// idx x -> x+1
void debug(int x){
if(!x) return;
debug(lc(x)),printf("%d ",tr[x].val),debug(rc(x));
return;
}
int main(void){
tr[0].mx=INF;
T=read(),n=read(),node(rt,1); // cnt = 1
while(n--){
int op=read();
if(op==1){
int x=read(),y; node(y,cnt+1);
++x;
int k=getrk(x);
int a,b; split(rt,a,b,k); merge(a,a,y); merge(rt,a,b);
}else if(op==2){
int y=read()+1,x=read()+1;
int a,b,c,k=getrk(y);
split(rt,a,b,k-1);
// printf("b_: "); debug(b); puts("");
splitv(b,b,c,y); merge(rt,a,c);
k=getrk(x);
// printf("b: "); debug(b); puts("");
int _a,_b,_c; split(rt,_a,_b,k-1); splitv(_b,_b,_c,y);
merge(_b,_b,b); merge(_b,_b,_c); merge(rt,_a,_b);
}else{
int y=read()+1;
printf("%d\n",getrk(y));
}
// debug(rt); puts("")
// for(int i=1;i<=cnt;++i){
// printf("rk = %d fa = %d size = %d lc = %d rc = %d\n",getrk(i),tr[i].fa,tr[i].siz,tr[i].lc,tr[i].rc);
// }
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
0 8 1 0 1 1 1 2 3 2 2 2 0 3 1 3 2 3 3
output:
3 4 1 2
result:
wrong answer 1st lines differ - expected: '2', found: '3'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 101ms
memory: 9012kb
input:
1 298913 1 0 3 1 3 1 3 1 3 1 3 1 1 0 1 0 3 3 1 2 1 2 3 5 3 5 1 1 1 3 1 4 3 3 1 3 1 6 3 7 3 2 3 5 3 8 3 2 1 8 3 3 1 4 3 2 3 7 1 3 3 4 1 10 3 14 3 13 1 12 3 4 1 8 1 15 1 16 3 9 3 14 3 10 3 8 3 7 1 16 1 15 3 16 3 13 1 19 3 13 3 1 3 14 1 18 1 22 3 8 1 17 3 18 3 9 1 18 3 9 3 1 1 20 3 11 3 5 3 2 3 22 1 22...
output:
2 2 2 2 2 2 4 4 2 4 5 6 8 5 2 5 4 8 15 3 8 4 19 18 12 5 14 3 3 19 22 13 18 4 4 23 23 7 6 21 6 18 23 28 19 24 32 5 2 20 22 13 23 35 34 6 23 41 41 9 15 43 36 10 41 25 19 14 37 9 26 50 33 35 48 15 48 20 39 11 15 32 41 18 21 46 47 2 36 2 44 10 48 34 57 3 9 20 42 22 19 51 23 62 28 3 3 7 5 59 63 36 62 60 ...
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 77ms
memory: 7152kb
input:
2 298235 1 0 1 1 3 2 1 0 1 3 3 4 3 3 3 3 3 2 3 4 3 2 3 3 1 2 3 3 1 4 1 2 1 1 3 5 3 8 1 5 1 9 3 10 3 8 3 10 3 5 3 8 3 5 1 2 1 9 3 5 3 7 3 12 3 3 1 6 3 4 3 3 3 11 3 8 3 9 3 7 3 6 3 4 1 12 1 11 3 13 3 13 1 11 3 16 3 6 3 14 3 9 3 5 3 13 1 9 1 17 3 16 3 13 3 5 3 15 3 8 3 4 3 13 1 18 3 15 3 16 3 19 3 4 1 ...
output:
3 3 2 2 5 3 5 2 2 9 6 11 6 11 9 6 9 10 9 12 2 3 2 9 7 12 10 4 3 5 5 10 4 16 14 13 5 10 5 13 11 7 3 5 11 10 17 3 16 14 14 8 4 4 12 22 8 6 5 3 11 6 16 21 7 18 13 6 25 5 16 14 8 11 18 7 20 10 20 20 13 4 19 17 22 20 27 13 26 22 20 11 15 25 9 9 15 17 33 9 15 34 31 15 5 2 21 22 38 23 26 8 19 28 29 36 38 1...
result:
wrong answer 1st lines differ - expected: '2', found: '3'
Subtask #4:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 299ms
memory: 7872kb
input:
3 299743 1 0 1 1 3 1 1 2 3 2 1 0 3 3 3 2 3 1 3 2 2 2 1 3 3 3 3 3 4 3 1 3 2 3 2 2 1 0 3 2 3 1 3 1 1 0 3 2 1 2 1 1 3 2 2 5 2 1 6 1 0 2 5 2 1 7 3 8 3 5 3 5 2 7 5 2 9 4 3 5 3 8 2 6 2 2 3 0 2 2 0 1 1 2 3 1 1 8 2 7 0 3 3 1 12 2 13 9 1 5 2 2 1 2 14 13 1 12 2 1 0 2 12 10 2 15 12 1 0 1 6 3 6 2 3 2 2 17 6 3 4...
output:
2 3 5 4 3 4 4 4 2 5 3 3 4 1 1 5 6 10 6 6 5 10 1 16 5 12 2 11 12 21 12 7 11 20 20 2 10 14 16 31 22 17 20 4 9 4 32 38 9 35 25 38 32 16 47 34 13 15 1 6 21 28 46 26 2 21 61 31 60 12 50 37 14 56 22 11 61 58 7 63 15 33 74 30 10 76 47 72 1 78 8 29 16 48 83 59 60 25 37 7 61 81 20 106 111 101 114 99 103 56 7...
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%