社区讨论
70pts RE求调!!!
P7073[CSP-J 2020] 表达式参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @m21u2mbb
- 此快照首次捕获于
- 2024/10/09 20:15 去年
- 此快照最后确认于
- 2025/11/04 17:33 4 个月前
CPP
#include<bits/stdc++.h>
//#include<windows.h>
using namespace std;
typedef long long ll;
typedef unsigned long long sll;
const int mod=1e9+7,INF=0x3f3f3f3f;
const long double pie=acos(-1);
inline int readINT()
{
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;
}
struct Tree{
int id,data;
Tree(){ }
Tree(int _id,int _data){
id=_id,data=_data;
}
}sta[1000005];
char cins[10];
int stop,n,x[100005],l,e[100005],q,res,f[200005],a[100005];
//x[i]表示第i个布尔是在哪里出现的。
//e[i]表示第i个字符串的下标
void push(Tree x){
sta[++stop]=x;
return;
}
void pop(){
stop--;
return;
}
Tree top(){
return sta[stop];
}
signed main(){
while(1){
scanf("%s",cins);
char tt=cins[0];
if(tt>='0'&&tt<='9')
break;
l++;
if(tt=='x'){
sscanf(cins+1,"%d",e+l);
x[e[l]]=l;
}
else if(tt=='&') e[l]=-1;
else if(tt=='|') e[l]=-2;
else if(tt=='!') e[l]=-3;
}
sscanf(cins,"%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",a+i);
for(int i=1;i<=l;i++){
if(e[i]>=0)
push({i,a[e[i]]});
else if(e[i]==-3){
Tree t=top();
pop();
push({i,!t.data});
f[t.id]=i;
}
else if(e[i]==-2){
Tree tl=top();pop();
Tree tr=top();pop();
push({i,tl.data||tr.data});
if(!tr.data)
f[tl.id]=i;
if(!tl.data)
f[tr.id]=i;
}
else{
Tree tl=top();pop();
Tree tr=top();pop();
push({i,tl.data&&tr.data});
if(tr.data)
f[tl.id]=i;
if(tl.data)
f[tr.id]=i;
}
}
int ans=top().data;
cin>>q;
while(q--){
scanf("%d",&res);
int t;
for(t=x[res];f[t];t=f[t]);
if(t==l)//能够改变到l
printf("%d\n",!ans);
else
printf("%d\n",ans);
}
return 0;
}
//-1 ->&
//-2 ->|
//-3 ->!
为啥我的代码RE啊
回复
共 3 条回复,欢迎继续交流。
正在加载回复...