QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#587297 | #7461. Fusion tree | Xiaohuba | 0 | 0ms | 0kb | C++23 | 4.2kb | 2024-09-24 19:13:07 | 2024-09-24 19:13:07 |
answer
#include <bits/stdc++.h>
using namespace std;
// #define LOCK_GETCHAR
// #define USE_INT_128
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif
#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif
#define il inline
#define mkp make_pair
#define fi first
#define se second
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k) \
for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) \
freopen(filename ".in", "r", stdin); \
freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif
// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on
// File head end
namespace {
constexpr ll MAXN = 5e5 + 5;
int n, m, fa[MAXN], a[MAXN], tag[MAXN], rt[MAXN], ch[MAXN * 21][2],
sz[MAXN * 21], val[MAXN * 21], cnt = 0;
vector<int> T[MAXN];
void dfs(int x, int pre) {
fa[x] = pre;
for (int v : T[x])
if (v != pre)
dfs(v, x);
}
void ins(int &p0, int x) {
if (!p0)
p0 = ++cnt;
int p = p0;
sz[p]++, val[p] ^= x;
For(i, 0, 20) {
int o = x >> i & 1;
if (!ch[p][o])
ch[p][o] = ++cnt;
p = ch[p][o], sz[p]++, val[p] ^= x >> (i + 1) << (i + 1);
}
}
void del(int p, int x) {
assert(p);
sz[p]--, val[p] ^= x;
For(i, 0, 20) {
int o = x >> i & 1;
assert(ch[p][o]);
p = ch[p][o], sz[p]--, val[p] ^= x >> (i + 1) << (i + 1);
}
}
void addOne(int dep, int p) {
if (dep == 21)
return;
swap(ch[p][0], ch[p][1]);
addOne(dep + 1, ch[p][1]);
val[p] =
val[ch[p][0]] ^ val[ch[p][1]] ^ ((sz[ch[p][1]] & 1) ? (1 << dep) : 0);
}
il void Main() {
read(n, m);
For(i, 1, n - 1) {
int u, v;
read(u, v), T[u].eb(v), T[v].eb(u);
}
For(i, 1, n) read(a[i]);
dfs(1, 0);
For(i, 1, n) for (int j : T[i]) if (j != fa[i]) ins(rt[i], a[j]);
// cerr << val[rt[2]] << ' ' << a[1] << '\n';
while (m--) {
int op, x, y;
read(op, x);
if (op == 1) {
if (fa[fa[x]])
del(rt[fa[fa[x]]], a[fa[x]] + tag[fa[fa[x]]]);
a[fa[x]]++;
if (fa[fa[x]])
ins(rt[fa[fa[x]]], a[fa[x]] + tag[fa[fa[x]]]);
tag[x]++;
addOne(0, rt[x]);
} else if (op == 2) {
read(y);
if (fa[x])
del(rt[fa[x]], a[x] + tag[fa[x]]);
a[x] -= y;
if (fa[x])
ins(rt[fa[x]], a[x] + tag[fa[x]]);
} else {
cout << (val[rt[x]] ^ (fa[x] ? (a[fa[x]] + tag[fa[fa[x]]]) : 0)) << '\n';
}
}
}
} // namespace
signed main() { return Main(), 0; }
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Runtime Error
input:
1000 998 1 2 2 3 2 4 3 5 5 6 2 7 5 8 1 9 8 10 7 11 3 12 9 13 8 14 12 15 9 16 6 17 8 18 2 19 19 20 7 21 21 22 14 23 15 24 1 25 13 26 16 27 3 28 17 29 15 30 11 31 1 32 25 33 4 34 32 35 12 36 11 37 24 38 16 39 14 40 17 41 17 42 39 43 35 44 40 45 18 46 10 47 19 48 23 49 21 50 3 51 27 52 46 53 19 54 5 55...
output:
result:
Test #2:
score: 0
Runtime Error
input:
732 927 1 2 1 3 2 4 2 5 3 6 6 7 6 8 8 9 5 10 7 11 9 12 2 13 3 14 14 15 5 16 2 17 16 18 12 19 2 20 4 21 1 22 4 23 13 24 2 25 25 26 5 27 7 28 3 29 7 30 28 31 26 32 29 33 3 34 22 35 15 36 9 37 36 38 22 39 26 40 10 41 39 42 1 43 33 44 11 45 18 46 9 47 32 48 38 49 38 50 17 51 15 52 23 53 22 54 1 55 41 56...
output:
result:
Test #3:
score: 0
Runtime Error
input:
888 957 1 2 1 3 1 4 4 5 2 6 3 7 4 8 6 9 8 10 10 11 9 12 9 13 4 14 12 15 1 16 5 17 15 18 14 19 12 20 17 21 7 22 10 23 18 24 7 25 14 26 17 27 17 28 5 29 9 30 10 31 1 32 9 33 15 34 5 35 29 36 5 37 31 38 8 39 15 40 16 41 38 42 36 43 39 44 42 45 24 46 10 47 17 48 38 49 27 50 49 51 50 52 13 53 28 54 14 55...
output:
result:
Test #4:
score: 0
Runtime Error
input:
98741 99956 74835 85030 85030 28368 74835 68215 68215 92388 74835 79089 28368 36904 79089 66465 74835 93241 28368 87962 28368 95370 74835 61859 28368 66251 66465 30174 68215 31110 74835 53487 79089 85715 85030 81833 28368 87215 66465 92843 92388 85032 68215 87899 93241 44543 93241 84738 28368 84503 ...
output:
result:
Test #5:
score: 0
Runtime Error
input:
98749 99996 74835 85030 85030 28368 85030 68215 85030 92388 68215 79089 92388 36904 74835 66465 85030 93241 74835 87962 92388 95370 92388 61859 36904 66251 68215 30174 85030 31110 68215 53487 92388 85715 79089 81833 36904 87215 85030 92843 74835 85032 68215 87899 74835 44543 68215 84738 85030 84503 ...
output:
result:
Test #6:
score: 0
Runtime Error
input:
98741 99956 74835 85030 85030 28368 28368 68215 28368 92388 28368 79089 28368 36904 92388 66465 68215 93241 28368 87962 28368 95370 92388 61859 68215 66251 66465 30174 93241 31110 68215 53487 95370 85715 74835 81833 74835 87215 87962 92843 66465 85032 93241 87899 95370 44543 92388 84738 28368 84503 ...
output:
result:
Test #7:
score: 0
Runtime Error
input:
500000 499998 490227 471442 490227 499003 490227 369864 490227 494579 490227 479601 490227 486294 490227 476073 490227 471990 490227 486941 490227 482358 490227 482292 490227 497143 490227 488454 490227 495448 490227 494294 490227 404800 490227 493828 490227 482597 490227 481109 490227 447198 490227...
output:
result:
Test #8:
score: 0
Runtime Error
input:
500000 499998 490227 471442 490227 499003 471442 369864 369864 494579 499003 479601 479601 486294 479601 476073 490227 471990 476073 486941 479601 482358 476073 482292 369864 497143 471990 488454 486294 495448 482292 494294 490227 404800 499003 493828 471990 482597 494579 481109 476073 447198 404800...
output:
result:
Test #9:
score: 0
Runtime Error
input:
500000 499998 490227 471442 471442 499003 471442 369864 499003 494579 490227 479601 490227 486294 490227 476073 471442 471990 499003 486941 490227 482358 471990 482292 486294 497143 494579 488454 471990 495448 499003 494294 479601 404800 494579 493828 486941 482597 404800 481109 369864 447198 476073...
output:
result:
Test #10:
score: 0
Runtime Error
input:
500000 499998 490227 471442 490227 499003 490227 369864 499003 494579 494579 479601 471442 486294 490227 476073 369864 471990 471990 486941 486941 482358 494579 482292 486941 497143 490227 488454 471442 495448 479601 494294 490227 404800 494579 493828 499003 482597 499003 481109 486294 447198 471442...