思路
双端队列,开指针数组记录位置,简单模拟。
代码
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node{
int num;
node *pre, *nxt;
};
node lis[100010];
node *pos[100010];
int a1[100010];
int n, m, cnt;
node *head, *p1, *p2, *t;
node* get_newone(int x){
node *newone = &lis[++cnt];
newone->num = x;
return newone;
}
void del(int x){
node *now = pos[x];
now->nxt->pre = now->pre;
now->pre->nxt = now->nxt;
return;
}
void print(){
for(node *i = p1->nxt; i != p2; i = i->nxt)
printf("%d ", i->num);
}
int main(){
scanf("%d", &n);
p1 = get_newone(0), p2 = get_newone(n+1);
t = get_newone(1);
p1->pre = NULL, p2->nxt = NULL;
p1->nxt = t, p2->pre = t;
t->nxt = p2, t->pre = p1;
pos[1] = t;
for(int i = 2; i <= n; i ++){
int a, b;
scanf("%d%d", &a, &b);
if(b == 0){ // left
node *now = pos[a];
node *newone = get_newone(i);
newone->nxt = now;
newone->pre = now->pre;
now->pre->nxt = newone;
now->pre = newone;
pos[i] = newone;
}else{ // right
node *now = pos[a];
node *newone = get_newone(i);
newone->nxt = now->nxt;
newone->pre = now;
now->nxt->pre = newone;
now->nxt = newone;
pos[i] = newone;
}
}
scanf("%d", &m);
for(int i = 1; i <= m; i ++) scanf("%d", &a1[i]);
sort(a1+1, a1+m+1), m = unique(a1+1, a1+m+1) - a1-1;
for(int i = 1; i <= m; i ++) del(a1[i]);
print();
return 0;
}