結果

問題 No.1641 Tree Xor Query
ユーザー chocoruskchocorusk
提出日時 2021-08-06 21:29:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 5,000 ms
コード長 1,795 bytes
コンパイル時間 3,371 ms
コンパイル使用メモリ 190,044 KB
実行使用メモリ 15,440 KB
最終ジャッジ日時 2023-10-17 02:47:52
合計ジャッジ時間 5,152 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,996 KB
testcase_01 AC 3 ms
6,996 KB
testcase_02 AC 3 ms
6,996 KB
testcase_03 AC 3 ms
7,000 KB
testcase_04 AC 3 ms
7,000 KB
testcase_05 AC 3 ms
7,000 KB
testcase_06 AC 3 ms
7,000 KB
testcase_07 AC 3 ms
7,000 KB
testcase_08 AC 3 ms
7,000 KB
testcase_09 AC 3 ms
7,000 KB
testcase_10 AC 3 ms
7,000 KB
testcase_11 AC 3 ms
7,000 KB
testcase_12 AC 3 ms
7,000 KB
testcase_13 AC 294 ms
15,440 KB
testcase_14 AC 293 ms
15,440 KB
testcase_15 AC 7 ms
7,160 KB
testcase_16 AC 19 ms
7,380 KB
testcase_17 AC 14 ms
7,208 KB
testcase_18 AC 11 ms
7,332 KB
testcase_19 AC 11 ms
7,036 KB
testcase_20 AC 203 ms
11,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s^=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)^sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]^=x;
            i+=(i&(-i));
        }
    }
};
int n, q;
vector<int> g[100010];
int c[100010];
int l[100010], r[100010], rev[100010];
int num;
void dfs(int x, int p){
    l[x]=num++;
    rev[l[x]]=x;
    for(auto y:g[x]){
        if(y==p) continue;
        dfs(y, x);
    }
    r[x]=num;
}
int main()
{
	cin>>n>>q;
    for(int i=0; i<n; i++){
        cin>>c[i];
    }
    for(int i=0; i<n-1; i++){
        int a, b; cin>>a>>b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, -1);
    BIT<int> bit(n);
    for(int i=0; i<n; i++) bit.add(l[i], c[i]);
    while(q--){
        int t; cin>>t;
        int x, y; cin>>x>>y; x--;
        if(t==1){
            bit.add(l[x], y);
        }else{
            cout<<bit.sum(l[x], r[x])<<endl;
        }
    }
    return 0;
}
0