码弱的链表查不出来问题QWQ
查看原帖
码弱的链表查不出来问题QWQ
496009
黄舀啊楼主2022/6/23 18:50

样例也没过

#include<iostream>
using namespace std;
const int MAXN = 1e5+10;

int n,cnt = 2,head,tail,m;

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
struct node{
	int v;
	int prep,next;
}Q[MAXN];
void build(){
	head = 0,tail = MAXN;
	Q[head].next = tail;
	Q[tail].prep = head;
	cnt = 2; 
}
void cut_in(int p,int value){
	int q = ++cnt;
	Q[q].prep = p;
	Q[q].next = Q[p].next;
	Q[Q[p].next].prep = q;
	Q[p].next = q;
	Q[q].v = value;
}
void remove(int p){
	Q[Q[p].prep].next = Q[p].next;
	Q[Q[p].next].prep = Q[p].prep;
	Q[p].v = -1;
}

int main(){
	
	n = read();
	build();
	cut_in(head,1);
//	cout << Q[Q[head].next].prep << ' ' << Q[Q[head].next].v << ' ' << Q[Q[head].next].next;
	for(int i=2,k,p ; i<=n ; i++){
		k = read(),p = read();
		if(p == 0){
			cut_in(k-1,i);
		} else {
			cut_in(k,i);
		}
	}
	m = read();
	for(int i=1,x ; i<=m ; i++){
		x = read();
		remove(x);
	}
	int lsp = head;
	while(Q[Q[lsp].next].v>0){
		cout << Q[Q[lsp].next].v << ' ';
		lsp = Q[lsp].next;
	}
	cout << endl;
	
	return 0;
} 
2022/6/23 18:50
加载中...