孩子写了一天了,AC#2#9#12#15,其余WA
#include<bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
x=0;int f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;
}
template <typename T> void print(T x){
if(x<0) x=-x,putchar('-');
if(x>9) print(x/10);
putchar(x%10+48);
}
int n,cnt=100000,q,t,tot;
bool f[100005];
char s;
struct node{
int type,l,r,val;
//type-> 1! 2& 3| 4数字
}a[1000005];
stack<int>st;
int dfs_get_num(int root){
if(a[root].type==4) return a[root].val;
if(a[root].type==1){//反
a[root].val=!dfs_get_num(a[root].l);
}
else if(a[root].type==2){//and
a[root].val=dfs_get_num(a[root].l) & dfs_get_num(a[root].r);
}
else{//or
a[root].val=dfs_get_num(a[root].l) | dfs_get_num(a[root].r);
}
return a[root].val;
}
void dfs_get_f(int root){
if(a[root].type==4){
f[root]=true;
return;
}
if(a[root].type==1){//反
dfs_get_f(a[root].l);
}
else if(a[root].type==2){//and
if(a[root].val==1){
dfs_get_f(a[root].l);
dfs_get_f(a[root].r);
}
else{//10 01 00
//a[root].val==0
if(a[root].l==0 and a[root].r==1) dfs_get_f(a[root].l);
else if(a[root].l==1 and a[root].r==0) dfs_get_f(a[root].r);
else return;
}
}
else{//or
if(!a[root].l and !a[root].r){
dfs_get_f(a[root].l);
dfs_get_f(a[root].r);
}
else{
if(a[root].l==0 and a[root].r==1) dfs_get_f(a[root].r);
else if(a[root].l==1 and a[root].r==0) dfs_get_f(a[root].l);
else return;
}
}
}
signed main(){
while(s=getchar()){
if(s=='\n') break;
if(s==' ') continue;
else if(s=='x'){
int num;
read(num);
a[num]=node{4,-1,-1,0};
st.push(num);
}//变量
else{
++cnt;
int u=st.top();st.pop();//左儿子
if(s=='!'){//取反,无右儿子
a[cnt]=node{1,u,-1,0};
st.push(cnt);
continue;
}
int v=st.top();st.pop();//右儿子
if(s=='&') {
a[cnt]=node{2,u,v,0};
st.push(cnt);
}
else if(s=='|'){
a[cnt]=node{3,u,v,0};
st.push(cnt);
}
}//符号
}
read(n);
for(int i=1;i<=n;i++) read(a[i].val);
dfs_get_num(cnt);
dfs_get_f(cnt);
read(t);
while(t--){
read(q);
if(f[q]) cout<<!a[cnt].val;
else cout<<a[cnt].val;
putchar('\n');
}
return 0;
}