#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
using namespace std;
int n, m, a[1000000], ptr, x[1000000], y[1000000];
struct Node
{
int x, sz;
bool on;
Node *l, *r;
Node () : x (0), l (NULL), r (NULL), on (false) {}
};
Node *root, *origin;
Node* dfs_init (int n, int tl, int tr)
{
if (n < tl) return origin;
Node* a = new Node ();
if (tl != tr)
{
a -> x = -(++ptr);
a -> l = dfs_init (n, tl, (tl + tr) / 2);
a -> r = dfs_init (n, (tl + tr) / 2 + 1, tr);
}
return a;
}
bool place_next (Node* t, int x)
{
t -> on = !(t -> on);
Node* to = new Node ();
if (t -> on) to = t -> l;
else to = t -> r;
if (to == origin) return false;
else if (to -> l == NULL) to -> x = x;
else return place_next (to, x);
return true;
}
void dfs_output (Node* t)
{
if (t -> x >= 0) return;
x[-(t -> x) - 1] = t -> l -> x;
y[-(t -> x) - 1] = t -> r -> x;
dfs_output (t -> l);
dfs_output (t -> r);
}
void create_circuit (int M, vector <int> A)
{
origin = new Node ();
int n = A.size ();
int start = 1;
while (start < n) start <<= 1;
root = dfs_init (n, 1, start);
int p = 0;
while (p != n)
if (place_next (root, A[p])) p++;
dfs_output (root);
vector <int> C;
C.push_back (root -> x);
for (int i = 0; i < m; i++)
C.push_back (0);
vector <int> X (ptr), Y (ptr);
for (int i = 0; i < ptr; i++)
{
X.push_back (x[i]);
Y.push_back (y[i]);
}
answer (C, X, Y);
}
Compilation message
doll.cpp: In constructor 'Node::Node()':
doll.cpp:28:12: warning: 'Node::r' will be initialized after [-Wreorder]
28 | Node *l, *r;
| ^
doll.cpp:26:7: warning: 'bool Node::on' [-Wreorder]
26 | bool on;
| ^~
doll.cpp:30:2: warning: when initialized here [-Wreorder]
30 | Node () : x (0), l (NULL), r (NULL), on (false) {}
| ^~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:111:2: error: 'answer' was not declared in this scope
111 | answer (C, X, Y);
| ^~~~~~