https://www.luogu.com.cn/problem/AT_abc344_e
#include<bits/stdc++.h>
#define int long long
#define il inline
namespace things{
il int rd(){
int f = 1, x = 0;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-' ) f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
il int max(int x, int y){
return std::max(x, y);
}
il int min(int a, int b){
return std::min(a, b);
}
}
using namespace things;
using namespace std;
const int N = 2e5 + 5;
int n, m, k, q, ans;
int a[N], b[N], c[N], x;
bool f;
string s[N], t;
map<int, int> pre, nxt;
signed main(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int i = 2; i <= n - 1; i++){
pre[a[i]] = a[i - 1];
nxt[a[i]] = a[i + 1];
}
pre[a[n]] = a[n - 1];
nxt[a[1]] = a[2];
int head = a[1], tail = a[n];
cin >> q;
while(q--){
int opt, x, y;
cin >> opt >> x;
if (opt == 1){
cin >> y;
if (x == tail) tail = y;
int nx = nxt[x];
pre[nx] = y;
nxt[x] = y;
pre[y] = x;
nxt[y] = nx;
}
else{
if (x == head){
head = nxt[head];
pre[head] = 0;
continue;
}
if (x == tail){
tail = pre[tail];
nxt[tail] = 0;
continue;
}
int p = pre[x], nx = nxt[x];
nxt[p] = nx;
pre[nx] = p;
pre[x] = 0;
nxt[x] = 0;
}
}
while(head != tail){
cout << head << " ";
head = nxt[head];
}
cout << tail;
return 0;
}