全WA求助(在本地能过)
查看原帖
全WA求助(在本地能过)
191281
Jr_Zlw楼主2020/11/25 14:04

下了官方数据点也都是能过的

但是一交到luogu,,,哪怕是自己上传的数据也是WA的

求助QAQ,谢谢大佬们

#include<bits/stdc++.h>
#define N 100001
//#define rep(a,b,c) for(register int c=(a);c<=(b);++c)
//#define drep(a,b,c) for(register int c=(a);c>=(b);--c)
using namespace std;
int l[N],x[N],s[N],loc[N],p,n,top;
char c[N];bool jud[N];
struct Tree{int f,l,r;bool v;}t[N];
inline void build()
{
	int i=1;
	for(int i=1;i<=p;++i)
	{
		if(l[i]) s[++top]=i,t[i].v=x[l[i]];
		else
		{
			if(c[i]!='!')
			{
				int x1=s[top--];
				int x2=s[top--];
				t[x1].f=t[x2].f=i;
				t[i].l=x2;t[i].r=x1;
//				cout<<t[x1].v<<' '<<t[x2].v<<'\n';
				if(c[i]=='|') t[i].v=(t[x1].v||t[x2].v);
				else t[i].v=(t[x1].v&&t[x2].v);
			}
			else
			{
				int x1=s[top--];
				t[i].l=x1;t[x1].f=i;
				t[i].v=(!t[x1].v);
			}
			s[++top]=i;
		}
	}return;
}
inline void dfs(int i)
{
    int L=t[i].l,R=t[i].r;
//    cout<<l<<r<<t[i].l<<t[i].r;
//    cout<<i<<"-->";
	if(!L&&!R)
	{
		jud[l[i]]=1;
//		cout<<l[i];
		return;
	}
	if(c[i]=='&')
	{
		if(!t[L].v&&!t[R].v){return;}
		if(t[L].v&&!t[R].v)dfs(R);
		if(t[L].v&&t[R].v)dfs(L),dfs(R);
		if(!t[L].v&&t[R].v)dfs(L);
		return;
	}
	if(c[i]=='|')
	{
		if(t[L].v&&t[R].v)return;
		if(!t[L].v&&!t[R].v)dfs(L),dfs(R);
		if(!t[L].v&&t[R].v)dfs(R);
		if(t[L].v&&!t[R].v)dfs(L);
		return;
	}
	else dfs(L);
    return;
}
int main()
{
	freopen("debug.txt","r",stdin);
	freopen("ans.txt","w",stdout);
	string in;
	while(cin>>in)
	{
		if(in.length()>1)
		{
			int res=0;
			for(int i=1;i<in.length();++i) res=(res<<1)+(res<<3)+(in[i]^48);
			l[++p]=res;loc[res]=p;
		}
		else c[++p]=in[0];
		if(in[0]<='9'&&in[0]>='0'&&in[0]!='x')
		{
			for(int i=0;i<in.length();++i) n=(n<<1)+(n<<3)+(in[i]^48);
			break;
		}
	}p--;
	for(int i=1;i<=n;++i) scanf("%d",&x[i]);
//	for(int i=1;i<=n;++i) cout<<x[i];puts("");
	int q;cin>>q;build();dfs(p);
	for(int i=1;i<=q;++i)
	{
		int m;scanf("%d",&m);
		cout<<(t[p].v^jud[m])<<'\n';
	}
	return 0;
}
2020/11/25 14:04
加载中...