Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34291 | LYLAKIOI | 【S】T2 | C++ | 通过 | 100 | 53 MS | 4376 KB | 1565 | 2024-11-05 18:35:44 |
#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define p_b push_back #define m_p make_pair typedef long long ll; using namespace std; const int maxn=4e5+10; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,a[maxn],b[maxn],fa[maxn],sz[maxn]; int fd(int x){ if(x==fa[x])return x; return fa[x]=fd(fa[x]); } void mg(int x,int y){ int a=fd(x),b=fd(y); if(a!=b)fa[a]=b,sz[b]+=sz[a]; } void slv(){ n=read();up(i,1,n)a[i]=read(),a[n+1]^=a[i]; up(i,1,n)b[i]=read();b[n+1]=-1; vector<int>A; up(i,1,n+1)if(a[i]!=b[i])A.p_b(a[i]);up(i,1,n)if(a[i]!=b[i])A.p_b(b[i]); int nw=(A.size()-1)/2; sort(A.begin(),A.end()); A.erase(unique(A.begin(),A.end()),A.end()); up(i,1,n+1)a[i]=lower_bound(A.begin(),A.end(),a[i])-A.begin()+1; up(i,1,n)b[i]=lower_bound(A.begin(),A.end(),b[i])-A.begin()+1; up(i,1,int(A.size()))fa[i]=i,sz[i]=1; //up(i,1,n)cout<<"! "<<a[i]<<" "<<b[i]<<endl; up(i,1,n)mg(a[i],b[i]); int res=0; up(i,1,int(A.size()))if(fd(i)==i)res++; //cout<<"res : "<<res<<" "<<A.size()<<endl; cout<<res+nw-(sz[fd(a[n+1])]!=1); } int main(){ //freopen("xor.in","r",stdin); //freopen("xor.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }