dp
by Chicky_Yang @ 2024-10-06 13:05:05
qp
by Loki_zhang @ 2024-10-06 16:53:52
qp
by qsc0909 @ 2024-10-06 16:54:09
qp
by sunkexuan @ 2024-10-06 17:29:49
```cpp
#include <bits/stdc++.h>
using namespace std;
int stk1[1000005],stk2[1000005],top1,top2;
char s[1000005];
int n,son[1000005][2],ans[1000005],ans2,ans3,flag11,flag22;
void build()
{
int x=stk1[top1--];
son[x][0]=stk2[top2-1];
son[x][1]=stk2[top2];
stk2[--top2]=x;
}
void dfs(int x)
{
if(isdigit(s[x])) return;
dfs(son[x][0]),dfs(son[x][1]);
if(s[x]=='&') ans[x]=ans[son[x][0]]&ans[son[x][1]];
if(s[x]=='|') ans[x]=ans[son[x][0]]|ans[son[x][1]];
}
void dfs2(int x)
{
if(isdigit(s[x])) return;
int ls=son[x][0],rs=son[x][1];
if(s[x]=='&')
{
if(ans[ls]==0) ans2++;
else dfs2(ls),dfs2(rs);
}
else if(s[x]=='|')
{
if(ans[ls]==1) ans3++;
else dfs2(ls),dfs2(rs);
}
else dfs2(ls),dfs2(rs);
}
int main()
{
cin>>(s+1);
n=strlen(s+1);
s[0]='(',s[n+1]=')';
for(int i=0;i<=n+1;i++)
{
if(s[i]=='|')
{
if(s[stk1[top1]]=='&') build();
if(s[stk1[top1]]=='|') build();
stk1[++top1]=i;
}
if(s[i]=='&')
{
if(s[stk1[top1]]=='&') build();
stk1[++top1]=i;
}
if(s[i]=='(') stk1[++top1]=i;
if(s[i]==')')
{
if(s[stk1[top1]]=='&') build();
if(s[stk1[top1]]=='|') build();
top1--;
}
if(isdigit(s[i]))
{
ans[i]=s[i]-'0';
stk2[++top2]=i;
}
}
dfs(stk2[top2]);
dfs2(stk2[top2]);
cout<<ans[stk2[top2]]<<'\n'<<ans2<<' '<<ans3<<'\n';
return 0;
}
```
by sapo1o @ 2024-10-06 18:18:32
qp
by chengzg @ 2024-10-06 18:45:29
@[tyakasha](/user/520777) 洛谷主题商店也没用力(大悲)
by NJYNsss @ 2024-10-06 18:53:25
@[ny_Dacong](/user/928972) 没用了吧
by NJYNsss @ 2024-10-06 18:53:59
@[MinimumSpanningTree](/user/398152) 觉得还是整一个深色模式比较好,原来的就不能调背景颜色
by NJYNsss @ 2024-10-06 18:57:18
原版
by liboya5074 @ 2024-10-06 20:16:36