# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197264 | stefdasca | Mechanical Doll (IOI18_doll) | C++14 | 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 "doll.h"
#include<bits/stdc++.h>
using namespace std;
int adja[400002], adjb[400002], sw = 1, tot, state[400002];
void build(int p, int st, int dr)
{
int mid = (st + dr) / 2;
if(st + 1 == dr)
{
if(tot <= mid)
adja[p] = 1;
return;
}
++sw;
adjb[p] = sw;
solve(sw, st, mid);
if(tot > mid)
{
++sw;
adja[p] = sw;
solve(sw, m+1, r);
}
else
adja[p] = 1;
}
void dfs(int nod, int val)
{
state[nod] ^= 1;
if(!state[nod])
{
if(adjb[nod])
dfs(adjb[nod], val);
else
adjb[nod] = val;
}
else
{
if(adja[nod])
dfs(adja[nod], val);
else
adja[nod] = val;
}
}
void create_circuit(int M, vector<int> A)
{
int N = A.size();
vector<int> C(M + 1);
C[0] = A[0];
A.push_back(0);
int sz = 1;
while(sz * 2 <= (int) A.size() - 1)
sz *= 2;
sz *= 2;
tot = A.size();
build(1, 1, sz);
for(int i = 0; i < A.size(); ++i)
dfs(1, -A[i]);
vector<int> X(sw), Y(sw);
for(int k = 0; k < sw; ++k)
{
X[k] = -adja[k];
Y[k] = -adjb[k];
}
answer(C, X, Y);
}