比赛 9.6 评测结果 AAAAAAAAAA
题目名称 平凡的测试数据 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.532 s
代码语言 C++ 内存使用 4.48 MiB
提交时间 2024-09-06 19:59:07
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 3e5+10;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

int n,m;
int a[N];
struct DSU{
	int fa[N],s[N];
	void build(){for(int i = 1;i <= n;i++)fa[i] = i,s[i] = a[i];}
	int find(int x){
		if(x == fa[x])return fa[x];
		int f = fa[x];
		fa[x] = find(fa[x]);
		s[x] ^= s[f] ^ a[f];
		return fa[x];
	}
	void merge(int x,int y){
		int yy = find(y);
		if(x == yy)return;
		fa[x] = y,s[x] = a[x] ^ s[y];
	}
}U;
int main(){
	freopen("td.in","r",stdin);
	freopen("td.out","w",stdout);
	n = read(),m = read();
	for(int i = 1;i <= n;i++)a[i] = read();
	U.build();
	for(int i = 1;i <= m;i++){
		int op = read(),x = read(),y = 0;
		if(op == 1){
			y = read();
			U.merge(x,y);
		}
		else U.find(x),printf("%d\n",U.s[x]);
	}

	return 0;

}