# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1122846 | sleepntsheep | Inspections (NOI23_inspections) | C11 | 0 ms | 324 KiB |
#include <stdio.h>
#define N 500005
int n, m, q, pa[N], ch[N][2], rev[N], jj = 200086, last, rt;
long long fresh[N], ss, ans[N], ans2[N];
void pus(int v) { if (rev[v]) { int t = ch[v][0]; ch[v][0] = ch[v][1]; ch[v][1] = t; rev[ch[v][0]] ^= 1; rev[ch[v][1]] ^= 1; rev[v] = 0; } }
void pul(int v) { if(!v) return; ans2[v] = ans2[ch[v][0]] + ans2[ch[v][1]] + ans[v]; }
int isroot(int v) { return ch[pa[v]][0] != v && ch[pa[v]][1] != v; }
void rot(int v) {
int p = pa[v], g = pa[p], d = ch[p][0] == v;
if (!isroot(p))
ch[g][ch[g][1] == p] = v;
ch[p][!d] = ch[v][d];
if (ch[v][d]) pa[ch[v][d]] = p;
pa[pa[ch[v][d] = p] = v] = g;
pul(p), pul(v);
}
void u____(int v) { if (!isroot(v)) u____(pa[v]); pus(v); }
void splay(int v) {
u____(v);
for (int p, g; !isroot(v); rot(v)) if (g = pa[p = pa[v]], !isroot(p)) rot((ch[g][0] == p) == (ch[p][0] == v) ? p : v);
pul(v);
}
void access(int v) { for (int w = 0; v; v = pa[w = v]) splay(v), ch[v][1] = w, pul(v); }
void makeroot(int v) { access(v), splay(v), rev[v] ^= 1; }
int findroot(int v) {
access(v), splay(v);
int r = v;
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |