比赛 20211014 评测结果 AAATTTTTTA
题目名称 平凡的测试数据 最终得分 40
用户昵称 ZRQ 运行时间 6.008 s
代码语言 C++ 内存使用 6.42 MiB
提交时间 2021-10-14 21:53:33
显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, w[300010], fa[300010], f, a, b; 
inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    return x * f;
}
int find(int x)
{
    if(x == fa[x]) return x;
    return fa[x] = find(fa[x]);
}
int main()
{
    freopen("td.in", "r", stdin);
    freopen("td.out", "w", stdout);
    n = read(); m = read();
    for(int i = 1; i <= n; ++i) w[i] = read();
    for(int i = 1; i <= n; ++i) fa[i] = i; 
    for(int i = 1; i <= m; ++i)
    {
        f = read(); a = read();
        if(f == 1)
        {
            b = read();
            for(int j = 1; j <= n; ++j)
                if(find(j) == a) w[j] ^= w[b];
            fa[a] = find(b);
        }
        else if(f == 2) printf("%d\n", w[a]);
    }
    return 0;
}