結果

問題 No.1641 Tree Xor Query
ユーザー hayatenhayaten
提出日時 2021-08-07 11:19:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 5,000 ms
コード長 2,148 bytes
コンパイル時間 5,314 ms
コンパイル使用メモリ 283,508 KB
実行使用メモリ 25,136 KB
最終ジャッジ日時 2023-10-17 17:48:52
合計ジャッジ時間 7,572 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 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 2 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 321 ms
25,136 KB
testcase_14 AC 327 ms
25,136 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 18 ms
4,960 KB
testcase_17 AC 14 ms
4,348 KB
testcase_18 AC 10 ms
4,432 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 219 ms
17,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define popcount(bit) __builtin_popcount(bit)
#define popcountll(bit) __builtin_popcountll(bit)
#define pb push_back
#define eb emplace_back
using namespace std;
using namespace atcoder;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Graph = vector<vector<int>>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll INF = (1LL <<60);

ll op(ll a, ll b) {
  return (a ^ b);
}
ll e() {
  return (ll)(0);
}

int dep[200002];
int in[200002];
int out[200002];
int k;
Graph G;

//通った頂点を並べたもの
vector<int> EularTour_V;
//通った辺を並べたもの
vector<int> EularTour_E;

void dfs(int v,int p, int d) {
  EularTour_V.pb(v);
  in[v] = k; k++;
  dep[v] = d;
  for (int u : G[v]){
    if(u ==p)continue;
    dfs(u, v, d + 1);
    EularTour_V.pb(v);
  }
  out[v] = k;
  k++;
}

//頂点iの部分木クエリは半開区間[in[i], out[i])となる。
//in[i]のみに値を入れる,out[i]には単位元を入れるとセグ木が正しく動く

int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> C(n);
  rep(i, n) cin >> C[i];
  G.resize(n);
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  dfs(0, -1, 0);
  vector<ll> res(EularTour_V.size());
  rep(i, n){
    res[in[i]] = C[i];
  }
  segtree<ll, op, e> seg(res);
  rep(i, q){
    int t;
    cin >> t;
    int a;
    ll b;
    cin >> a >> b;
    a--;
    if(t == 1){
      ll c = seg.get(in[a]);
      seg.set(in[a], c ^ b);
    }else{
      cout << seg.prod(in[a], out[a]) << endl;
    }
  }
}
0