# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40443 | szawinis | Birthday gift (IZhO18_treearray) | C++14 | 2045 ms | 105188 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int N = 1 << 18;
int n, m, q, a[N];
vector<int> g[N];
set<int> pos[N], lca_pos[N];
int d[N];
vector<int> anc[N];
void dfs(int u, int p) {
for(int v: g[u]) if(v != p) {
d[v] = d[u] + 1;
anc[v].push_back(u);
for(int j = 0; 1 << j+1 <= d[v]; j++)
anc[v].push_back(anc[anc[v][j]][j]);
dfs(v, u);
}
}
int lca(int u, int v) {
if(d[v] > d[u]) swap(u, v);
if(d[u] > d[v]) {
for(int j = 0; 1 << j <= d[u] - d[v]; j++)
if(d[u] - d[v] >> j & 1) u = anc[u][j];
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... |