为啥这题开 O2会RE?
  • 板块P1160 队列安排
  • 楼主卷王慢即快
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/4/12 13:45
  • 上次更新2023/10/28 03:55:07
查看原帖
为啥这题开 O2会RE?
494699
卷王慢即快楼主2022/4/12 13:45

我不懂为啥不开优化就能过,开了就RE。

#include<cstdio>
using namespace std;
struct node {
	int key,pre,next;
	node(int k=0,int p=0,int n=0)
		{pre=p;next=n;key=k;}
};
node t[100005];
int find[100005]={0},tot=0;
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<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int left_push(int x,int y)
{
	int now=find[x];
	t[++tot]=node(y,t[now].pre,now);
	find[y]=tot;
	t[t[now].pre].next=tot;
	t[now].pre=tot;
}
int right_push(int x,int y)
{
	int now=find[x];
	t[++tot]=node(y,now,t[now].next);
	find[y]=tot;
	t[t[now].next].pre=tot;
	t[now].next=tot;
}
void insert(int x)
{
	int now=find[x];
	t[t[now].pre].next=t[now].next;
	t[t[now].next].pre=t[now].pre;
	find[x]=0;
}
int main()
{
	right_push(0,1);
	int n,m;
	n=read();
	t[0]=node();
	for(int i=2;i<=n;i++)
	{
		int x,p;
		x=read();p=read();
		if(p==0) left_push(x,i);
		else right_push(x,i);
	}
	m=read();
	for(int i=1;i<=m;i++)
	{
		int x;
		x=read();
		if(find[x]) insert(x);
	}
	int now=t[0].next;
	while(now)
	{
		printf("%d ",t[now].key);
		now=t[now].next;
	}
	return 0;
}
2022/4/12 13:45
加载中...