# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380855 | 2021-03-23T10:16:20 Z | VodkaInTheJar | popa (BOI18_popa) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "popa.h" using namespace std; int solve(int n, int *left, int *right) { int last = 0; left[last] = -1, right[last] = -1; par[last] = -1; vector <int> par(n); for (int i = 1; i < n; i++) { int prv = last; while (last != -1 && !query(last, i, last, last)) { prv = last; last = par[last]; } if (last == -1) { par[prv] = i; left[i] = prv; right[i] = -1; } else { if (right[last] == -1) { right[last] = i; left[i] = -1; right[i] = -1; par[i] = last; } else { left[i] = right[last]; par[left[i]] = i; right[i] = -1; right[last] = i; } } last = i; } while (par[last] != -1) last = par[last]; return last; }