結果

問題 No.1641 Tree Xor Query
ユーザー
提出日時 2021-08-10 21:38:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4,003 ms / 5,000 ms
コード長 1,532 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 104,068 KB
実行使用メモリ 14,384 KB
最終ジャッジ日時 2024-09-22 23:14:10
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0