快 20%。
没啥用。
/* test.cpp */
#include <bits/stdc++.h>
#define fo(x) freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout);
using i64 = long long; using u32 = unsigned;
// #define SOLVE_TOPO
#define RELABEL
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n, q; u32 seed;
n = 2e4, q = 4e4, seed = 0; // std::cin >> n >> q >> seed;
std::cerr << "n = " << n << " q = " << q << " seed = " << seed << '\n';
std::mt19937 rnd(seed);
std::vector<u32> a(n); for (auto &x : a) x = rnd();
std::vector<int> fa(n, -1);
std::vector<std::vector<int>> adj(n);
for (int i = 1; i < n; ++i)
fa[i] = rnd() % i, adj[fa[i]].push_back(i);
std::cerr << "Generate: " << double(clock()) / CLOCKS_PER_SEC << "s\n";
#ifdef RELABEL
std::vector<int> in(n), seq; int cnt = 0;
[&]() {
std::vector<int> sz(n, 1);
for (int i = n; --i; ) sz[fa[i]] += sz[i];
auto dfs = [&](auto self, int u) -> void {
in[u] = cnt++, seq.push_back(u);
for (auto &v : adj[u]) if (sz[v] > sz[adj[u].front()]) std::swap(v, adj[u].front());
for (auto v : adj[u]) self(self, v);
};
dfs(dfs, 0);
std::vector<int> ofa = fa;
std::vector<std::vector<int>> oadj(n); std::swap(adj, oadj);
std::vector<u32> oa = a;
for (int i = 0; i < n; ++i) {
if (i) fa[in[i]] = in[ofa[i]];
adj[in[i]] = std::move(oadj[i]), a[in[i]] = oa[i];
for (auto &x : adj[in[i]]) x = in[x];
}
}();
std::cerr << "Relabel: " << double(clock()) / CLOCKS_PER_SEC << "s\n";
#endif
auto f = [&](u32 x) -> u32 { return x << 19 | x >> 13; };
auto dfs = [&](auto self, int u) -> u32 {
u32 h = a[u];
for (auto v : adj[u]) h += f(self(self, v));
return h;
};
auto b = a;
u32 ans = 0;
for (int _ = 0; _ < q; ++_) {
int p = rnd() % n; u32 x = rnd();
#ifdef RELABEL
p = in[p];
#endif
a[p] = x;
#ifdef SOLVE_TOPO
b = a;
for (int i = n; --i; ) b[fa[i]] += f(b[i]);
ans ^= b[0];
#else
ans ^= dfs(dfs, 0);
#endif
}
std::cout << ans << '\n';
std::cerr << "All: " << double(clock()) / CLOCKS_PER_SEC << "s\n";
return 0;
}