<JZOJ5910>duliu
2024-10-08 19:02:18
愤怒
考场想到正解
然后觉得我的“正解”和正解差不多 一样的效果
被忽略的与正解的不同也想到了
然而 我懒得再写
于是快乐10分
气坏了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#define rint register int
using std::sort;
using std::map;
//using std::cout;
//using std::endl;
template <class T>inline void read(T &X)
{
X=;int W=;char ch=;
while(!isdigit(ch))W|=ch=='-',ch=getchar();
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
X=W?-X:X;return;
}
int n,cnt=,ans=;
long long sta[],end[],xors=,xore=,sta2[],end2[],fa[];
bool boo(true);
long long find(long long x){return fa[x]==x?x:fa[x]=find(fa[x]);}
map<int,int>num;
int main()
{
// freopen("duliu.in","r",stdin);
// freopen("duliu.out","w",stdout);
read(n);
for(rint i=;i<=n;++i)
read(sta[i]),sta2[i]=sta[i],xors^=sta[i];
sta[n+]=xors;sta2[n+]=xors;
for(rint i=;i<=n;++i)
{
read(end[i]),end2[i]=end[i];
xore^=end[i];
if(xors==end[i])boo=false;
}
end[n+]=xore;end2[n+]=xore;
++n;
sort(sta2+,sta2+n+);
sort(end2+,end2+n+); for(rint i=;i<=n;++i)
{
if(sta2[i]!=end2[i]){printf("-1\n");return ;}
}
cnt=;
for (int i=;i<=n;i++)
{
if (sta[i]!=end[i]||i==n)
{
if (i<n) ans++;
if (!num[sta[i]]) cnt++,num[sta[i]]=cnt;
if (!num[end[i]]) cnt++,num[end[i]]=cnt;
}
}
if (ans==)
{
printf("0\n");
return ;
}
for (int i=;i<=cnt;i++) fa[i]=i;
for (int i=;i<=n;i++) if (sta[i]!=end[i]) fa[find(num[sta[i]])]=find(num[end[i]]);
for (int i=;i<=cnt;i++) if (fa[i]==i) ans++;
printf("%d\n",ans-);
return ;
}
最新文章
- webrtc中APM(AudioProcessing module)的使用
- C#输出文本树形层次,前或者后自定义空格位数
- 利用history实现无刷新跳转界面
- 轻量级Lua IDE ZeroBrane Studio 的使用技巧和汉化
- 炉石复盘 宇宙法vs复活牧 [20161130]
- Sql助手
- 【python之路7】python基本数据类型(一)
- 使用SQLCipher加密数据库
- Windows下与Linux下编写socket程序的区别 《转载》
- PredictionIO+Universal Recommender快速开发部署推荐引擎的问题总结(2)
- 作业五:RE 模块模拟计算器
- [UWP 自定义控件]了解模板化控件(1):基础知识
- AD 16 下绘图的几个技巧
- C#:单元测试(VS2015)
- 小程序开发 绑定自定义数据data- 及JS获取
- mongodb 远程访问配置
- 解题:POI 2014 Ant colony
- December 11th 2016 Week 51st Sunday
- kvm虚拟主机安装速度很慢
- JS学习之函数的属性和方法