結果

問題 No.1641 Tree Xor Query
ユーザー 小高悠太郎
提出日時 2025-09-05 08:42:53
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 418 ms / 5,000 ms
コード長 1,465 bytes
コンパイル時間 3,600 ms
コンパイル使用メモリ 295,472 KB
実行使用メモリ 30,436 KB
最終ジャッジ日時 2025-09-05 08:43:00
合計ジャッジ時間 6,502 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define fore(i, a) for(auto &i:a)
using ll = long long;
#include<atcoder/lazysegtree>
using namespace atcoder;

struct S{
	ll value;
};
S op(S a, S b){
	return S{a.value^b.value};
}
S e(){
	return S{0};
}
struct F{
	ll value;
};
S mapping(F f, S x){
	return S{x.value^f.value};
}
F composition(F f, F g){
	return F{f.value^g.value};
}
F id(){
	return F{0};
}
int main() {
	ll n, q;
	cin >> n >> q;
	vector<ll> c(n);
	rep(i, n){
		cin >> c[i];
	}
	vector<vector<ll>> G(n);
	rep(i, n-1){
		ll a, b;
		cin >> a >> b;
		a--;b--;
	  G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<ll> pre(n), post(n);
	ll cnt = 0;
	function<void(ll,ll)> dfs = [&](ll x, ll last){
		pre[x] = cnt++;
		fore(to, G[x]){
			if(to == last)continue;
			dfs(to, x);
		}
		post[x] = cnt++;
	};
	dfs(0, -1);
	vector<S> vec(2*n);
	rep(i, n){
		vec[pre[i]] = S{c[i]};
		vec[post[i]] = S{0};
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> seg(vec);
	vector<tuple<ll,ll,ll>> qs(q);
	rep(i, q){
		ll t, x, y;
		cin >> t >> x >> y;
		x--;
		qs[i] = {t, x, y};
	}
	rep(i, q){
		auto[t, x, y] = qs[i];
		if(t == 1){
			seg.apply(pre[x], F{y});
		}
		else{
      cout << seg.prod(pre[x], post[x]).value << endl;
		}
	}
	

	
}
0