45求调(悬关)
查看原帖
45求调(悬关)
901379
ltl0825楼主2024/6/29 19:15

不知为啥45,找了一下午,晚上还是没找到错误 有哪位大佬帮忙看看吗,谢谢。

#include<bits/stdc++.h>
using namespace std;
char str[1010];
int n,q,ans,a[1000010],y,b[2000010],l=0,c[1000010],f[2000010]={0};
stack<pair<int,int>> s;
int main()
{
	while(1)
	{
		scanf("%s",str);
		if(str[0] >= '0' && str[0] <= '9') 
		{
			break;
		}
		l++;
		if(str[0]=='x')
		{
			sscanf(str+1,"%d",b+l);
			c[b[l]]=l;
		}
		if(str[0]=='&')
		{
			b[l]=-1;
		}
		if(str[0]=='|')
		{
			b[l]=-2;
		}
		if(str[0]=='!')
		{
			b[l]=-3;
		}
	}
	sscanf(str,"%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=l;i++)
	{
		if(b[i]>0)
		{
			s.push({i,a[b[i]]});
		}
		if(b[i]==-3)
		{
			auto tmp=s.top();
			s.pop();
			s.push({i,!tmp.second});
			f[tmp.first]=i;
		}
		if(b[i]==-2)
		{
			auto tmp=s.top();
			s.pop();
			auto tmp1=s.top();
			s.pop();
			s.push({i,tmp.second||tmp1.second});
			if(!tmp1.second)
			{
				f[tmp.first]=i;
			}
			if(!tmp.second)
			{
				f[tmp1.first]=i;
			}
		}
		if(b[i]==-1)
		{
			auto tmp=s.top();
			s.pop();
			auto tmp1=s.top();
			s.pop();
			s.push({i,tmp.second&&tmp1.second});
			if(!tmp1.second)
			{
				f[tmp.first]=i;
			}
			if(!tmp.second)
			{
				f[tmp1.first]=i;
			}
		}
	}
	ans=s.top().second;
	scanf("%d",&q);
	int x;
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&x);
		for(y=c[x];f[y];y=f[y])
		{
			
		}
		printf("%d\n",y==l?(!ans):(ans));
	}
	return 0;
}
2024/6/29 19:15
加载中...