ABC E 求条
  • 板块学术版
  • 楼主Esperance
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/9 21:47
  • 上次更新2024/3/9 23:33:34
查看原帖
ABC E 求条
550545
Esperance楼主2024/3/9 21:47
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
#define int long long
int a[maxn], l[maxn], r[maxn], tot = 0;
map<int,int> pos;
map<int,int> v;
void inst(int x,int i) {
	v[++tot] = x;
	pos[x] = tot;
	r[tot] = r[i]; r[i] = tot; l[tot] = i; l[r[tot]] = tot; 
}
void del(int i) {
	l[r[i]] = l[i]; r[l[i]] = r[i];
	pos[v[i]] = 0; l[i] = r[i] = 0;
}
int n, m;
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1;i <= n;i++) cin >> a[i];
	for (int i = 1;i <= n;i++) inst(a[i],i-1);
	cin >> m;
	while (m--) {
		int op, x, y;
		cin >> op >> x;
		if (op == 1) {
			cin >> y;
			inst(y,pos[x]);
		}
		else del(pos[x]);
	}
	int head = 0, tail = 0;
	for (int i = 0;!i;i = r[i]) head = r[i];
	for (int i = head;i;i = r[i]) {
		cout << v[i] << ' ';
	}
	return 0;
}
2024/3/9 21:47
加载中...