結果

問題 No.1641 Tree Xor Query
ユーザー 夜
提出日時 2021-08-10 21:38:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,979 ms / 5,000 ms
コード長 1,532 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 103,048 KB
実行使用メモリ 14,536 KB
最終ジャッジ日時 2023-10-24 06:25:47
合計ジャッジ時間 6,865 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,376 KB
testcase_01 AC 5 ms
9,376 KB
testcase_02 AC 5 ms
9,376 KB
testcase_03 AC 5 ms
9,376 KB
testcase_04 AC 6 ms
9,376 KB
testcase_05 AC 5 ms
9,376 KB
testcase_06 AC 6 ms
9,376 KB
testcase_07 AC 5 ms
9,376 KB
testcase_08 AC 5 ms
9,376 KB
testcase_09 AC 5 ms
9,376 KB
testcase_10 AC 7 ms
9,376 KB
testcase_11 AC 6 ms
9,376 KB
testcase_12 AC 6 ms
9,376 KB
testcase_13 AC 299 ms
14,536 KB
testcase_14 AC 301 ms
14,536 KB
testcase_15 AC 9 ms
9,876 KB
testcase_16 AC 21 ms
10,132 KB
testcase_17 AC 16 ms
9,876 KB
testcase_18 AC 13 ms
9,876 KB
testcase_19 AC 13 ms
9,376 KB
testcase_20 AC 3,979 ms
14,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n, q;
vector<vector<int>> vec(100010);
bool bo[100010] = { false };
int c[100010], in[100010], out[100010], d[200020];
vector<long long> BIT(500050);
void add(long long i, long long x) {
	while (i <= 2 * n) {
		BIT[i] ^= x;
		i += i & -i;
	}
}
long long csum(long long i) {
	long long count = 0;
	while (i > 0) {
		count ^= BIT[i];
		i -= i & -i;
	}
	return count;
}
long long sum(long long l, long long r) {
	return csum(r) ^ csum(l - 1);
}
int main() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		vec[a].emplace_back(b);
		vec[b].emplace_back(a);
	}
	stack<int> st;
	st.push(1);
	in[1] = 1;
	add(1, c[1]);
	bo[1] = true;
	int co = 2;
	while (!st.empty()) {
		int now = st.top();
		bool bo1 = false;
		for (int i = 0; i < vec[now].size(); i++) {
			if (!bo[vec[now][i]]) {
				bo[vec[now][i]] = true;
				bo1 = true;
				st.push(vec[now][i]);
				add(co, c[vec[now][i]]);
				in[vec[now][i]] = co;
				co++;
				break;
			}
		}
		if (!bo1) {
			out[now] = co;
			co++;
			st.pop();
		}
	}
	for (int i = 0; i < q; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		if (t == 1) {
			add(in[x], y);
		}
		else {
			cout << sum(in[x], out[x]) << endl;
		}
	}
}
0