比赛 9.6 评测结果 AAAAAAAAAA
题目名称 平凡的测试数据 最终得分 100
用户昵称 darkMoon 运行时间 0.705 s
代码语言 C++ 内存使用 5.38 MiB
提交时间 2024-09-06 19:53:27
显示代码纯文本
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;
auto IN = freopen("td.in", "r", stdin);
auto OUT = freopen("td.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 3e5 + 5;
int n = mread(), m = mread(), a[N], fa[N], s[N];
pair<int, int> findfa(int x){
    if(x == fa[x]){
        return mp(x, 0);
    }
    int tmp = fa[x];
    auto t = findfa(fa[x]);
    fa[x] = t.fi;
    if(tmp != fa[x]){
        s[x] ^= t.se;
    }
    return mp(t.fi, s[x]);
}
signed main(){
    for(int i = 1; i <= n; i ++){
        a[i] = mread();
        fa[i] = i;
        s[i] = a[i];
    }
    while(m --){
        int op = mread();
        if(op == 1){
            int x = mread(), y = mread();
            if(x == y){
                continue;
            }
            fa[x] = y;
        }
        else{
            int x = mread();
            printf("%lld\n", findfa(x).se ^ a[fa[x]]);
        }
    }
    return 0;
}