记录编号 355271 评测结果 AAAAAAAAAA
题目名称 平凡的测试数据 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.220 s
提交时间 2016-11-24 11:25:03 内存使用 3.97 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <string>
#include <list>
#include <queue>
#include <vector>
using namespace std;
char buf[1<<18], *fs, *ft;
inline char readc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++;
}
inline int fast_read()
{
    int r;
    char c;
    bool sig = false;
    while(c = readc())
    {
        if(c >= '0' && c <= '9')
        {
            r = c^0x30;
            break;
        }else if(c == '-')sig = true;
    }
    while(isdigit(c = readc()))
        r = (r<<3)+(r<<1)+(c^0x30);
    return sig?-r:r;
}
// --------------------------------
int n, m;
#define MAXN 300001
int f[MAXN], val[MAXN], tval[MAXN];
int get_f(int x)
{
    if(x == f[x])return x;
    int orif = f[x];
    f[x] = get_f(orif);
    if(f[x] != orif)
        tval[x] ^= tval[orif];
    return f[x];
}
int main()
{
    freopen("td.in", "r", stdin);
    freopen("td.out", "w", stdout);
    n = fast_read();
    m = fast_read();
    for(int i = 1; i <= n; i++)f[i] = i;
    for(int i = 1; i <= n; i++)tval[i] = val[i] = fast_read();
    for(int i = 1; i <= m; i++)
    {
        int op = fast_read();
        if(op == 1)
        {
            int x, y;
            x = fast_read();
            y = fast_read();
            f[x] = y;
        }else{
            int x = fast_read();
            int y = get_f(x);
            if(f[x] == x)printf("%d\n", tval[x]);
            else printf("%d\n", tval[x]^tval[f[x]]);
        }
    }
    return 0;
}