QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791206 | #21403. 文艺平衡树 | jager59 | WA | 0ms | 3816kb | C++14 | 2.0kb | 2024-11-28 17:27:14 | 2024-11-28 17:27:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int n,m,a[N],rt,tot;
struct TREE{
int son[2],fa,siz,val,tag;
}t[N];
inline void up(int p){
t[p].siz=t[t[p].son[0]].siz+1+t[t[p].son[1]].siz;
}
inline int build(int f,int l,int r){
if(l>r)return 0;
int mid = l+r>>1,p=++tot;
t[p].son[0]=build(p,l,mid-1),t[p].son[1]=build(p,mid+1,r);
t[p].val=a[mid];t[p].fa=f;
up(p);
return p;
}
inline void cg(int p){
t[p].tag^=1;swap(t[p].son[0],t[p].son[1]);
}
inline void spread(int x){
if(t[x].tag){
if(t[x].son[0])cg(t[x].son[0]);
if(t[x].son[1])cg(t[x].son[1]);
}
}
inline void rotate(int x){
int y=t[x].fa,z=t[y].fa,k=(x==t[y].son[1]);
spread(y);spread(x);
t[x].fa=z,t[z].son[y==t[z].son[1]]=x;
t[y].son[k]=t[x].son[k^1];t[t[x].son[k^1]].fa=y;
t[x].son[k^1]=y,t[y].fa=x;
up(y);up(x);
}
inline void splay(int x,int goal){
while(t[x].fa!=goal){
int y=t[x].fa,z=t[y].fa;
if(z!=goal)(x==t[y].son[1])^(y==t[z].son[1])?rotate(x):rotate(y);
rotate(x);
}
if(!goal)rt=x;
}
inline int kth(int k){
int p = rt;
while(1){
spread(p);
if(k<=t[t[p].son[0]].siz)p=t[p].son[0];
else{
k-=t[t[p].son[0]].siz+1;
if(!k)return p;
p=t[p].son[1];
}
}
}
inline void dfs(int p){
if(!p)return;
spread(p);
dfs(t[p].son[0]);
if(t[p].val)printf("%d ",t[p].val);
dfs(t[p].son[1]);
}
int main(){
n=read(),m=read();
for(int i = 1;i<=n;i++)a[i]=i;
rt=build(0,0,n+1);
while(m--){
int l = read(),r=read();
l=kth(l),r=kth(r+2);
// cerr<<l<<' '<<r<<endl;
splay(l,0),splay(r,l);
cg(t[r].son[0]);
}
dfs(rt);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3816kb
input:
30 5 7 26 7 18 5 9 4 15 3 15
output:
1 2 3 14 11 8 9 10 7 27 28 29 30 19 20 21 22 15 5 6 4 12 16 17 18 13 23 24 25 26
result:
wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 3 14 11 8 9 10 7 27 28 29 ...6 4 12 16 17 18 13 23 24 25 26 '