#include "doll.h"
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 1e6 + 5;
int l[mxN], r[mxN], name[mxN];
int X[mxN], Y[mxN], state[mxN];
int cur = 1, take;
vector<int> ord;
void build(int x, int lx, int rx) {
if (lx == rx) return;
l[x] = 2 * x;
r[x] = 2 * x + 1;
int mx = (lx + rx) >> 1;
build(2 * x, lx, mx);
build(2 * x + 1, mx + 1, rx);
}
int compress(int x) {
if (!l[x]) {
take--;
return 1e9;
}
int rr = compress(r[x]);
int ll = -1;
if (take) ll = compress(l[x]);
name[x] = cur++;
X[name[x]] = ll, Y[name[x]] = rr;
return name[x];
}
void find_leaf(int x, int par = 0) {
if (x == -1) {
return;
}
if (x == 1e9) {
ord.push_back(par);
return;
}
if (state[x]) find_leaf(Y[x], x);
else find_leaf(X[x], x);
state[x] ^= 1;
}
void create_circuit(int m, vector<int> A) {
vector<int> c(m + 1);
c[0] = A[0];
if (A.size() == 1) {
answer(c, {}, {});
return;
}
vector<int> ad[m + 1];
A.push_back(0);
for (int i = 0; i + 1 < A.size(); i++) {
ad[A[i]].push_back(A[i + 1]);
}
int need = 0;
for (int i = 1; i <= m; i++) {
need += ad[i].size();
}
int x = 1;
while (x < need) x *= 2;
build(1, 1, x);
take = need;
compress(1);
while (ord.size() < need) {
find_leaf(name[1]);
}
for (int i = 1; i < cur; i++) {
if (X[i] == -1) X[i] = -name[1];
else X[i] *= -1;
Y[i] *= -1;
}
for (int i = 0; i < ord.size(); i++) {
if (i + 1 < A.size() - 1) {
if (X[ord[i]] == -1e9) X[ord[i]] = A[i + 1];
else Y[ord[i]] = A[i + 1];
} else if (i + 1 < ord.size()) {
if (X[ord[i]] == -1e9) X[ord[i]] = -name[1];
else Y[ord[i]] = -name[1];
} else {
Y[ord[i]] = 0;
}
}
for (int i = 1; i < c.size(); i++) c[i] = -name[1];
vector<int> retx(cur - 1), rety(cur - 1);
for (int i = 1; i < cur; i++) {
retx[i - 1] = X[i];
rety[i - 1] = Y[i];
}
answer(c, retx, rety);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:53:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i + 1 < A.size(); i++) {
| ~~~~~~^~~~~~~~~~
doll.cpp:65:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | while (ord.size() < need) {
| ~~~~~~~~~~~^~~~~~
doll.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int i = 0; i < ord.size(); i++) {
| ~~^~~~~~~~~~~~
doll.cpp:74:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if (i + 1 < A.size() - 1) {
| ~~~~~~^~~~~~~~~~~~~~
doll.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | } else if (i + 1 < ord.size()) {
| ~~~~~~^~~~~~~~~~~~
doll.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 1; i < c.size(); i++) c[i] = -name[1];
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
49 ms |
10424 KB |
Output is correct |
3 |
Correct |
44 ms |
9796 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
70 ms |
14528 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
49 ms |
10424 KB |
Output is correct |
3 |
Correct |
44 ms |
9796 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
70 ms |
14528 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
81 ms |
14008 KB |
Output is correct |
9 |
Correct |
89 ms |
16984 KB |
Output is correct |
10 |
Correct |
132 ms |
23060 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
49 ms |
10424 KB |
Output is correct |
3 |
Correct |
44 ms |
9796 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
70 ms |
14528 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
81 ms |
14008 KB |
Output is correct |
9 |
Correct |
89 ms |
16984 KB |
Output is correct |
10 |
Correct |
132 ms |
23060 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
131 ms |
20688 KB |
Output is correct |
15 |
Correct |
83 ms |
13492 KB |
Output is correct |
16 |
Correct |
120 ms |
19448 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
312 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
125 ms |
21584 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
64 ms |
9648 KB |
Output is correct |
3 |
Correct |
70 ms |
9720 KB |
Output is correct |
4 |
Correct |
104 ms |
15204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
64 ms |
9648 KB |
Output is correct |
3 |
Correct |
70 ms |
9720 KB |
Output is correct |
4 |
Correct |
104 ms |
15204 KB |
Output is correct |
5 |
Correct |
126 ms |
19708 KB |
Output is correct |
6 |
Correct |
131 ms |
18936 KB |
Output is correct |
7 |
Correct |
123 ms |
19140 KB |
Output is correct |
8 |
Correct |
115 ms |
18072 KB |
Output is correct |
9 |
Correct |
68 ms |
11360 KB |
Output is correct |
10 |
Correct |
109 ms |
17836 KB |
Output is correct |
11 |
Correct |
104 ms |
17380 KB |
Output is correct |
12 |
Correct |
69 ms |
12156 KB |
Output is correct |
13 |
Correct |
82 ms |
12352 KB |
Output is correct |
14 |
Correct |
77 ms |
13276 KB |
Output is correct |
15 |
Correct |
78 ms |
13712 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
72 ms |
11360 KB |
Output is correct |
18 |
Correct |
69 ms |
11276 KB |
Output is correct |
19 |
Correct |
69 ms |
11960 KB |
Output is correct |
20 |
Correct |
107 ms |
17196 KB |
Output is correct |
21 |
Correct |
104 ms |
17068 KB |
Output is correct |
22 |
Correct |
105 ms |
16684 KB |
Output is correct |