社区讨论
关于我一道sb题打了个并查集还t了这件事
P7073[CSP-J 2020] 表达式参与者 20已保存回复 27
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 27 条
- 当前快照
- 1 份
- 快照标识符
- @lo7tlyn2
- 此快照首次捕获于
- 2023/10/27 07:33 2 年前
- 此快照最后确认于
- 2023/10/27 07:33 2 年前
本机下载数据测0.8s,交上去t,求教卡常或debug
CPP#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int maxs=1e6+10;
int fa[maxn<<2];
int sta[maxn<<1];
int son[maxn<<1][2];
int dp[maxn<<1];
char S[maxs];
int top;
int find(int x)
{
while(x!=fa[x]) x=fa[x];
return x;
}
int ya(int x)
{
int fax=find(x);
while(x!=fax)
{
int tmp=fa[x];
fa[x]=fax,x=tmp;
}
return fax;
}
void init(int x)
{
son[x][0]=x,son[x][1]=x+200000;
fa[x]=x,fa[x+200000]=x+200000;
}
int main()
{
scanf("%[^\r\n]",S);
int n;scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&dp[i]);
char ch;int beg=0,N=n;
do
{
char s[10];
sscanf(S+beg,"%[^ ]",s);
if(s[0]=='x')
{
int x;sscanf(s+1,"%d",&x);
sta[++top]=x,init(x);
}
else if(s[0]=='!')
{
int x=sta[top];dp[x]^=1;
swap(son[x][0],son[x][1]);
}
else if(s[0]=='&')
{
int x=sta[top],y=sta[top-1];
dp[++N]=dp[x]&dp[y],sta[--top]=N,init(N);
fa[son[x][0]]=son[N][0],fa[son[x][1]]=son[N][dp[y]];
fa[son[y][0]]=son[N][0],fa[son[y][1]]=son[N][dp[x]];
}
else
{
int x=sta[top],y=sta[top-1];
dp[++N]=dp[x]|dp[y],sta[--top]=N,init(N);
fa[son[x][0]]=son[N][dp[y]],fa[son[x][1]]=son[N][1];
fa[son[y][0]]=son[N][dp[x]],fa[son[y][1]]=son[N][1];
}
beg+=sprintf(s,"%s",s)+1;
}while(~sscanf(S+beg-1,"%c",&ch));
int q;scanf("%d",&q);
while(q--)
{
int x;scanf("%d",&x);
printf("%d\n",(ya(son[x][dp[x]^1])!=N)^(son[N][0]!=N));
}
return 0;
}
回复
共 27 条回复,欢迎继续交流。
正在加载回复...