QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#587300 | #7461. Fusion tree | Xiaohuba | 100 ✓ | 510ms | 188636kb | C++23 | 4.2kb | 2024-09-24 19:15:01 | 2024-09-24 19:15:01 |
Judging History
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][0]);
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; }
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 3ms
memory: 10312kb
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:
57016 28035 26032 48408 5370 29101 67519 109095 33590 64911 126995 81187 88168 7987 65831 20294 28038 76748 78948 86276 101544 13018 70500 83265 42317 98596 95400 83134 106380 19144 57473 90898 81082 7987 65894 75939 62994 98619 26298 26929 21165 13029 41437 65756 14271 68114 6285 75939 71309 24308 ...
result:
ok 314 numbers
Test #2:
score: 10
Accepted
time: 0ms
memory: 10084kb
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:
130015 113111 91673 85411 85125 41666 98019 7932 125229 94292 13462 96596 36371 90751 87116 18346 71942 78872 24693 91231 29880 75019 118901 8073 51994 12486 13405 123883 90212 27788 29659 125141 98020 96162 85104 46876 90992 11089 6716 11874 4770 23686 56774 71325 66371 115696 90871 24123 19419 164...
result:
ok 332 numbers
Test #3:
score: 10
Accepted
time: 3ms
memory: 10204kb
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:
67461 48909 26042 55488 51236 14531 75845 97843 17799 47699 72297 27897 99318 36144 23600 109593 88295 63638 8742 88783 80067 25251 104583 6006 67710 96795 63548 92974 17591 22145 94439 73606 98534 98280 50908 90342 78570 43013 63903 8742 32489 31670 97686 43013 54991 28047 27538 69881 112267 29122 ...
result:
ok 334 numbers
Test #4:
score: 10
Accepted
time: 61ms
memory: 34340kb
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:
81557 18637 73617 81557 112176 68510 18637 54859 109169 8234 120581 13220 51859 73617 118213 106788 118213 73617 118250 68515 10367 90340 68516 73618 1798 83274 93666 16254 93668 121722 67950 79710 1933 118871 8239 67950 1933 128594 79710 13224 18474 128594 123822 8240 54869 9769 128590 94783 48677 ...
result:
ok 33314 numbers
Test #5:
score: 10
Accepted
time: 50ms
memory: 33788kb
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:
32088 64357 112324 47966 43450 68475 112320 48075 56165 112572 43450 73397 112573 32095 44281 93366 11989 44230 90663 44231 32099 70357 13765 6996 70357 32101 6996 93368 32101 110023 110023 77112 110023 93369 68106 69093 70358 93372 81048 39836 48081 104904 72391 48084 69984 77120 15934 69984 83581 ...
result:
ok 33344 numbers
Test #6:
score: 10
Accepted
time: 69ms
memory: 36332kb
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:
4389 114642 15903 77607 2699 4384 44934 50758 21291 23446 102650 111236 15874 23446 60379 21291 102649 105949 36816 102649 11297 71901 44934 43323 11310 110222 11642 44934 110222 91569 118236 42091 7514 122279 49694 102138 74054 65765 113235 57970 27318 35643 27036 21292 23453 98863 74054 65765 2703...
result:
ok 33396 numbers
Test #7:
score: 10
Accepted
time: 296ms
memory: 58268kb
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:
73018 116647 123236 51958 109255 109255 47792 57456 73022 73022 73022 73022 27167 73022 27788 27788 27788 73022 109486 16287 27638 73022 73022 78690 73022 33490 73022 73022 73024 73024 97393 73026 35191 73028 116237 6250 6250 6250 73028 100032 119869 100596 47522 73029 56261 73029 50528 73030 3377 7...
result:
ok 166956 numbers
Test #8:
score: 10
Accepted
time: 460ms
memory: 157588kb
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:
20228 47265 12485 68229 95709 17704 27545 25190 26150 66720 48679 51426 30669 64643 5475 16788 38164 71110 38721 82428 70607 75348 99218 92697 79434 88981 120911 90775 71110 8591 125363 69747 70488 58169 69747 95776 88625 124197 21979 50600 85100 51431 56593 112753 83607 95811 16789 78132 70913 6644...
result:
ok 166117 numbers
Test #9:
score: 10
Accepted
time: 510ms
memory: 173128kb
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:
59216 3058 94919 71000 6103 109660 6572 125190 23318 57746 43228 30768 125107 124309 113235 65454 43307 21330 65998 116268 65464 79004 127169 129746 50155 43617 111032 124309 109663 129487 1241 5953 3323 129554 28277 98087 46510 90920 88664 126558 93398 51180 84474 79752 75285 106182 48826 4597 9449...
result:
ok 167027 numbers
Test #10:
score: 10
Accepted
time: 492ms
memory: 188636kb
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...
output:
35258 59899 87322 72963 123268 30765 106046 68572 70062 78139 57494 22720 12800 124444 91199 47193 13182 17298 123468 114503 23034 86694 23095 112269 117067 94968 36329 112507 101746 80499 53053 26124 66770 37866 120292 17071 75917 90033 21681 97945 48851 33331 72890 14717 3375 94895 59900 23475 488...
result:
ok 166392 numbers
Extra Test:
score: 0
Extra Test Passed