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 "doll.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/home/ioi/contests/ioi18_d2/debug.h"
#else
#define debug(...) void(37)
#endif
void create_circuit(int M, std::vector<int> A) {
A.push_back(0);
int N = A.size();
/*
std::vector<int> C(M + 1);
C[0] = -1;
for (int i = 1; i <= M; ++i) {
C[i] = 1;
}
std::vector<int> X(N), Y(N);
for (int k = 0; k < N; ++k) {
X[k] = Y[k] = A[k];
}
answer(C, X, Y);
*/
int S = 1;
while (S < N) {
S *= 2;
}
vector<int> X, Y;
auto Dfs = [&](int l, int r, auto&& Dfs) {
if (S - r > N) {
return -1;
}
if (l == r) {
return 0;
}
int mid = (l + r) / 2;
int v = int(X.size());
X.push_back(-1);
Y.push_back(-1);
int left = Dfs(l, mid, Dfs);
int right = Dfs(mid + 1, r, Dfs);
X[v] = left, Y[v] = right;
return -1 - v;
};
Dfs(0, S - 1, Dfs);
int n = int(X.size());
vector<int> p(n);
for (int i = 0; i < N; ++i) {
int v = 0;
while (true) {
int to = (p[v] ? Y[v] : X[v]);
p[v] ^= 1;
if (to == 0) {
break;
}
v = -to - 1;
}
(p[v] ? X[v] : Y[v]) = A[i];
}
answer(vector<int>(M + 1, -1), X, Y);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |