結果

問題 No.1641 Tree Xor Query
ユーザー trineutrontrineutron
提出日時 2021-08-06 22:44:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 5,000 ms
コード長 1,606 bytes
コンパイル時間 3,184 ms
コンパイル使用メモリ 255,120 KB
実行使用メモリ 21,416 KB
最終ジャッジ日時 2023-10-17 04:13:28
合計ジャッジ時間 4,585 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 297 ms
21,416 KB
testcase_14 AC 292 ms
21,416 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 17 ms
4,404 KB
testcase_17 AC 13 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 200 ms
14,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;

using graph = vector<vector<int>>;

int op(int a, int b)
{
    return a ^ b;
}

int e()
{
    return 0;
}

void tour(const graph &to, vector<int> &route, int v, int p)
{
    route.push_back(v);
    for (auto &&c : to.at(v))
    {
        if (c == p)
        {
            continue;
        }
        tour(to, route, c, v);
    }
    route.push_back(v);
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> c.at(i);
    }
    graph to(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to.at(a).push_back(b);
        to.at(b).push_back(a);
    }
    vector<int> route;
    tour(to, route, 0, -1);
    assert(int(route.size()) == 2 * n);
    vector<int> idx0(n, -1), idx1(n, -1);
    for (int i = 0; i < 2 * n; i++)
    {
        int v = route.at(i);
        if (idx0.at(v) == -1)
        {
            idx0.at(v) = i;
        }
        else
        {
            assert(idx1.at(v) == -1);
            idx1.at(v) = i;
        }
    }
    segtree<int, op, e> seg(2 * n);
    for (int i = 0; i < n; i++)
    {
        seg.set(idx0.at(i), c.at(i));
    }
    for (int i = 0; i < q; i++)
    {
        int t, x, y;
        cin >> t >> x >> y;
        x--;
        if (t == 1)
        {
            seg.set(idx0.at(x), seg.get(idx0.at(x)) ^ y);
        }
        else
        {
            cout << seg.prod(idx0.at(x), idx1.at(x)) << '\n';
        }
    }
    return 0;
}
0