用的是stl库里的list
#include <iostream>
#include <list>
using namespace std;
list<int> l;
int main(){
l.push_back(1);
int n, c, x, y;
auto it=l.begin();
cin >> n;
for(int i=1;i <= n;i++){
cin >> c;
if(c == 1){
cin >> x >> y;
if(l.back() == x){
l.push_back(y);
continue;
}
for(it=l.begin();it != l.end();it++){
if(*it == x){
it++;
l.insert(it, y);
}
}
}
else if(c == 2){
cin >> x;
if(l.back() == x){
cout << "0\n";
continue;
}
for(it=l.begin();it != l.end();it++){
if(*it == x){
++it;
cout << *it << "\n";
break;
}
}
}
else{
cin >> x;
l.remove(x);
}
}
return 0;
}