双向链表
#include<bits/stdc++.h>
using namespace std;
int q,op,x,y,f[1000010];
struct node{
int pre,ne;
}a[1000010];
void insert(int x,int y){
int tn=a[x].ne;
a[x].ne=y;
a[y].pre=x;
a[y].ne=tn;
a[tn].pre=y;
}
void erase(int x){
a[a[x].pre].ne=a[x].ne;
a[a[x].ne].pre=a[x].pre;
}
int main(){
cin>>q;
while(q--){
cin>>op>>x;
if(op==1){
cin>>y;
if(f[x]){
insert(0,x);
}
insert(x,y);
}
else if(op==2){
cout<<a[x].ne<<endl;
}
else{
erase(x);
}
}
return 0;
}
感谢各位神犇的指导!!