結果
| 問題 |
No.1641 Tree Xor Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 22:53:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,240 bytes |
| コンパイル時間 | 2,459 ms |
| コンパイル使用メモリ | 205,860 KB |
| 最終ジャッジ日時 | 2025-01-23 16:06:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 10 |
ソースコード
#line 1 "/workspaces/compro/lib/template.hpp"
#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>
#ifndef IO_VECTOR
#define IO_VECTOR
template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
int size = v.size();
for (int i = 0; i < size; i++) {
std::cout << v[i];
if (i != size - 1)
std::cout << " ";
}
return out;
}
template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
for (auto &el : v) {
std::cin >> el;
}
return in;
}
#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
}
#line 2 "main.cpp"
void solve(ll N, ll Q, const std::vector<int> &C, const std::vector<long long> &a, const std::vector<long long> &b,
const std::vector<long long> &T, const std::vector<long long> &x, const std::vector<int> &y) {
ll M = 2 * sqrt(N * Q);
vector<int> cost = C;
vector<int> dp(N, 0);
vector<vector<int>> g(N);
REP(i, N - 1) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
vector<bool> isLarge(N, false);
vector<int> parent(N);
auto dfs = [&](int cur, int par, auto self) -> void {
int s = 0;
dp[cur] = cost[cur];
parent[cur] = par;
for (const auto &el : g[cur]) {
if (el == par)
continue;
self(el, cur, self);
dp[cur] ^= dp[el];
s++;
}
if (s > M)
isLarge[cur] = true;
};
dfs(0, -1, dfs);
REP(i, Q) {
if (T[i] == 1) {
cost[x[i]] ^= y[i];
dp[x[i]] ^= y[i];
int target = parent[i];
while (target != -1 && isLarge[target]) {
cost[target] ^= y[i];
dp[target] ^= y[i];
target = parent[target];
}
} else {
if (isLarge[x[i]]) {
cout << dp[x[i]] << endl;
} else {
int ans = cost[x[i]];
for (const auto &el : g[x[i]]) {
if (el == parent[x[i]])
continue;
ans ^= dp[el];
}
cout << ans << endl;
}
}
}
}
// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
std::cin >> N;
std::vector<int> C(N);
vl a(N - 1), b(N - 1);
std::cin >> Q;
std::vector<long long> T(Q), x(Q);
vi y(Q);
for (int i = 0; i < N; ++i) {
std::cin >> C[i];
}
for (int i = 0; i < N - 1; ++i) {
std::cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
for (int i = 0; i < Q; ++i) {
std::cin >> T[i] >> x[i] >> y[i];
x[i]--;
}
solve(N, Q, C, a, b, T, x, y);
return 0;
}