比赛 20170912 评测结果 AAAAAAAAAA
题目名称 平凡的测试数据 最终得分 100
用户昵称 Mayuri 运行时间 0.474 s
代码语言 C++ 内存使用 2.60 MiB
提交时间 2017-09-12 19:50:38
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

#define ll long long
#define mem(Arr,x) memset(Arr,x,sizeof(Arr))

const int maxN=300001;
const int inf=2147483647;

int n,m;
int Mayuri[maxN];
int Mayuri_dist[maxN];

int read();
int Find(int x);

int main()
{
	freopen("td.in","r",stdin);
	freopen("td.out","w",stdout);
	n=read();
	m=read();
	for (int i=1;i<=n;i++)
	{
		Mayuri[i]=i;
		Mayuri_dist[i]=read();
	}
	for (int i=1;i<=m;i++)
	{
		//for (int j=1;j<=n;j++)
		//	cout<<Mayuri[j]<<" "<<Mayuri_dist[j]<<endl;
		//cout<<endl;
		int op=read();
		if (op==1)
		{
			int u=read(),v=read();
			Mayuri[u]=v;
		}
		else
		{
			int x=read();
			int fx=Find(x);
			if (x==Mayuri[x])
				printf("%d\n",Mayuri_dist[x]);
			else
				printf("%d\n",Mayuri_dist[x]^Mayuri_dist[fx]);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

int read()
{
	int x=0;
	int k=1;
	char ch=getchar();
	while (((ch>'9')||(ch<'0'))&&(ch!='-'))
		ch=getchar();
	if (ch=='-')
	{
		k=-1;
		ch=getchar();
	}
	while ((ch>='0')&&(ch<='9'))
	{
		x=x*10+ch-48;
		ch=getchar();
	}
	return x*k;
}

int Find(int x)
{
	if (Mayuri[x]==x)
		return x;
	if (Mayuri[Mayuri[x]]==Mayuri[x])
		return Mayuri[x];
	int fx=Find(Mayuri[x]);
	Mayuri_dist[x]=Mayuri_dist[x]^Mayuri_dist[Mayuri[x]];
	Mayuri[x]=fx;
	return Mayuri[x];
}