# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500254 | sidon | Mechanical Doll (IOI18_doll) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
#include "doll.h"
vector<int> s, x(1<<18), y(1<<18), z(1<<18);
int cnt, v = -1, rt = -1, b, n;
int dfs(int l, int r) {
if(l >= n) return -1;
if(r - l < 2) {
return 1;
} else {
int m = (l + r) / 2;
int u = cnt++;
y[u] = dfs(l, m);
x[u] = dfs(m, r);
return -u-1;
}
}
void create_circuit(int M, vector<int> A) {
s.assign(M+1, -1);
x.assign(2*N, 0);
y.assign(2*N, 0);
z.assign(2*N, 0);
A.push_back(0);
cnt = b = 0, v = -1, rt = -1, n = size(A);
while((1<<b)<n) ++b;
dfs(0, 1<<b);
for(int &i : A) {
int u = 0;
while(u >= 0) {
z[u] ^= 1;
int w = -1-(z[u] ? x[u] : y[u]);
if(w < 0) {
(z[u] ? x[u] : y[u]) = i;
rt = u; u = -1;
} else u = w;
}
}
if(n > 2) {
x[cnt] = -1-cnt;
y[rt] = -1-cnt++;
}
x.resize(cnt);
y.resize(cnt);
answer(s, x, y);
}