結果

問題 No.1641 Tree Xor Query
ユーザー carrot46carrot46
提出日時 2021-08-06 21:55:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,898 bytes
コンパイル時間 2,430 ms
コンパイル使用メモリ 212,648 KB
実行使用メモリ 17,364 KB
最終ジャッジ日時 2023-10-17 03:17:30
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 218 ms
17,364 KB
testcase_14 AC 219 ms
17,364 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 129 ms
14,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
//#pragma GCC optimize("Ofast")
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

using T = int;
int op(int a, int b){
    return a ^ b;
}
int e(){
    return 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N>>Q;
    vec c(N), f(N), g(N);
    rep(i, N) cin>>c[i];
    mat G(N);
    rep(i, N - 1){
        int a, b;
        cin>>a>>b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    {
        int t{};
        auto dfs = [&](auto &&self, int p, int v) -> void{
            f[v] = t++;
            for(int to : G[v]) if(to != p) self(self, v, to);
            g[v] = t++;
        };
        dfs(dfs, -1, 0);
    }
    segtree<T, op, e> seg(N * 2);
    auto add = [&](int p, T x){
        seg.set(p, op(seg.get(p), x));
    };
    rep(i, N) add(f[i], c[i]);
    while(Q--){
        int t, x, y;
        cin>>t>>x>>y;
        --x;
        if(t == 1){
            add(x, y);
        }else{
            cout<<seg.prod(f[x], g[x])<<endl;
        }
    }
}
0