#include "doll.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
vi X, Y;
struct Node {
Node *x = 0, *y = 0;
bool state = false;
int left_son = 0, right_son = 0;
int sz = 2;
Node(int d) {
if (!d) {
return;
}
x = new Node(d - 1);
y = new Node(d - 1);
left_son = 1, right_son = 1;
sz = x->sz + y->sz;
}
void First(int &a) {
if (!x) {
right_son = 1;
a--;
if (a > 0) {
left_son = 1;
a--;
}
return;
}
y->First(a);
if (a > 0) x->First(a);
}
bool Delete() {
if (!x) {
return !left_son && !right_son;
}
if (y->Delete()) {
delete y;
right_son = 0;
y = 0;
}
if (x->Delete()) {
delete x;
left_son = 0;
x = 0;
}
sz = (x ? x->sz : 1) + (y ? y->sz : 1);
return !left_son && !right_son;
}
bool Add(int a) {
state = !state;
if (state) {
if (!x) {
if (left_son <= 0) {
left_son = -1;
return false;
}
left_son = a;
return true;
}
return x->Add(a);
}
else {
if (!y) {
if (right_son <= 0) {
right_son = -1;
return false;
}
right_son = a;
return true;
}
return y->Add(a);
}
}
int Create() {
int node = X.size();
X.push_back(-1), Y.push_back(-1);
if (!x) X[node] = left_son;
else {
int a = x->Create();
X[node] = a;
}
if (!y) Y[node] = right_son;
else {
int a = y->Create();
Y[node] = a;
}
node = -node - 1;
return node;
}
};
int Solve(vi &v) {
int n = v.size();
int bit = 0;
for (int a = 1; a < n; bit++, a <<= 1);
bit--;
Node tree(bit);
tree.First(n);
n = v.size();
tree.Delete();
// for (int i = n; i < tree.sz; i++) tree.Add(-1);
for (int i = 0; i < n; i++) {
while (!tree.Add(v[i]));
}
// tree.Add(v.back());
tree.Create();
return -1;
}
void create_circuit(int m, std::vector<int> a) {
X.clear(), Y.clear();
int n = a.size();
a.push_back(0);
int t = a[0];
a.erase(a.begin());
if (a.size() == 1 || a.empty()) {
vi c(m + 1, 0);
c[0] = t;
answer(c, X, Y);
return;
}
Solve(a);
vi c(m + 1, -1);
c[0] = t;
answer(c, X, Y);
}
//5 14
//1 2 3 3 2 5 1 1 2 1 4 3 4 3
//1 7
//1 1 1 1 1 1 1
//1 20
//1 1 1 1 1
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:124:9: warning: unused variable 'n' [-Wunused-variable]
124 | int n = a.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
7164 KB |
Output is correct |
3 |
Correct |
57 ms |
9036 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
12240 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
7164 KB |
Output is correct |
3 |
Correct |
57 ms |
9036 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
12240 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
76 ms |
13636 KB |
Output is correct |
9 |
Correct |
109 ms |
16580 KB |
Output is correct |
10 |
Correct |
141 ms |
22108 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
7164 KB |
Output is correct |
3 |
Correct |
57 ms |
9036 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
12240 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
76 ms |
13636 KB |
Output is correct |
9 |
Correct |
109 ms |
16580 KB |
Output is correct |
10 |
Correct |
141 ms |
22108 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
142 ms |
21640 KB |
Output is correct |
15 |
Correct |
106 ms |
15900 KB |
Output is correct |
16 |
Correct |
134 ms |
21488 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
142 ms |
21636 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
85 ms |
12504 KB |
Output is correct |
3 |
Correct |
96 ms |
15204 KB |
Output is correct |
4 |
Correct |
141 ms |
20652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
85 ms |
12504 KB |
Output is correct |
3 |
Correct |
96 ms |
15204 KB |
Output is correct |
4 |
Correct |
141 ms |
20652 KB |
Output is correct |
5 |
Correct |
131 ms |
21420 KB |
Output is correct |
6 |
Correct |
140 ms |
21380 KB |
Output is correct |
7 |
Correct |
155 ms |
21396 KB |
Output is correct |
8 |
Correct |
133 ms |
21296 KB |
Output is correct |
9 |
Correct |
104 ms |
15196 KB |
Output is correct |
10 |
Correct |
131 ms |
21260 KB |
Output is correct |
11 |
Correct |
124 ms |
20996 KB |
Output is correct |
12 |
Correct |
83 ms |
15476 KB |
Output is correct |
13 |
Correct |
72 ms |
12880 KB |
Output is correct |
14 |
Correct |
82 ms |
15760 KB |
Output is correct |
15 |
Correct |
80 ms |
15712 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
81 ms |
12676 KB |
Output is correct |
18 |
Correct |
88 ms |
12692 KB |
Output is correct |
19 |
Correct |
82 ms |
15384 KB |
Output is correct |
20 |
Correct |
128 ms |
21124 KB |
Output is correct |
21 |
Correct |
150 ms |
20944 KB |
Output is correct |
22 |
Correct |
148 ms |
21120 KB |
Output is correct |