#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
struct node {
int l = INT_MIN, r = INT_MIN, y = 0, valid = 0, d = 0;
};
int timer = 2, dep, vl, vr;
vector<int> x, y;
node tree[500005];
void build(int n, int d) {
tree[n].d = d;
if (dep-1 == d) {
return;
}
tree[n].l = -timer;
timer++;
tree[n].r = -timer;
timer++;
build(-tree[n].l, d+1);
build(-tree[n].r, d+1);
}
void find(int n, int d, int l, int r) {
int m = (l+r)/2;
if (dep-1 == d) {
if (tree[n].y == 0) {
vl = l;
vr = l;
} else {
vl = r;
vr = r;
}
} else {
if (tree[n].y == 0) {
find(-tree[n].l, d+1, l, m);
} else {
find(-tree[n].r, d+1, m+1, r);
}
}
}
void create(int n, int d, int v) {
if (dep-1 == d) {
if (tree[n].y == 0) {
tree[n].l = v;
} else {
tree[n].r = v;
}
} else {
if (tree[n].y == 0) {
create(-tree[n].l, d+1, v);
} else {
create(-tree[n].r, d+1, v);
}
}
tree[n].y ^= 1;
}
void clean(int n, int d) {
if (dep-1 == d) {
if (tree[n].l != INT_MIN || tree[n].r != INT_MIN) {
tree[n].valid = 1;
}
} else {
clean(-tree[n].l, d+1);
clean(-tree[n].r, d+1);
tree[n].valid |= tree[-tree[n].l].valid;
tree[n].valid |= tree[-tree[n].r].valid;
}
}
void create_circuit(int m, vector<int> a) {
vector<int> d(m+1, 0);
d[0] = a[0];
if (a.size() == 1) {
answer(d, x, y);
return;
}
d[a[0]] = -1;
for (int i : a) {
d[i] = -1;
}
int n = a.size(), s;
dep = ceil(log2(n));
s = 1 << dep;
build(1, 0);
int acl = 1, acr = s-(n-s/2);
int j = 1;
for (int i = 1; i < s; i++) {
find(1, 0, 1, s);
if ((s/2) < vl && vl <= acr) {
create(1, 0, INT_MIN);
} else {
create(1, 0, a[j]);
j++;
}
}
create(1, 0, 0);
clean(1, 0);
int co = 1;
vector<int> conv(s, 0);
for (int i = 1; i < s; i++) {
if (tree[i].valid == 0) {
continue;
}
conv[i] = co;
co++;
}
for (int i = 1; i < s; i++) {
if (tree[i].valid == 0) {
continue;
}
if (tree[i].l >= 0) {
x.push_back(tree[i].l);
} else if (tree[i].l == INT_MIN || tree[-tree[i].l].valid == 0) {
x.push_back(-1);
} else {
x.push_back(-conv[-tree[i].l]);
}
if (tree[i].r >= 0) {
y.push_back(tree[i].r);
} else if (tree[i].r == INT_MIN || tree[-tree[i].r].valid == 0) {
y.push_back(-1);
} else {
y.push_back(-conv[-tree[i].r]);
}
}
answer(d, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:83:9: warning: unused variable 'acl' [-Wunused-variable]
83 | int acl = 1, acr = s-(n-s/2);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
5336 KB |
Output is correct |
3 |
Correct |
48 ms |
6220 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
55 ms |
8732 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
5336 KB |
Output is correct |
3 |
Correct |
48 ms |
6220 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
55 ms |
8732 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
61 ms |
9192 KB |
Output is correct |
9 |
Correct |
102 ms |
12848 KB |
Output is correct |
10 |
Correct |
106 ms |
15292 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
35 ms |
5336 KB |
Output is correct |
3 |
Correct |
48 ms |
6220 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
1624 KB |
Output is correct |
6 |
Correct |
55 ms |
8732 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
61 ms |
9192 KB |
Output is correct |
9 |
Correct |
102 ms |
12848 KB |
Output is correct |
10 |
Correct |
106 ms |
15292 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
110 ms |
15040 KB |
Output is correct |
15 |
Correct |
94 ms |
12084 KB |
Output is correct |
16 |
Correct |
105 ms |
14784 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
109 ms |
15052 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
55 ms |
7756 KB |
Output is correct |
3 |
Correct |
92 ms |
10688 KB |
Output is correct |
4 |
Correct |
102 ms |
12992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
55 ms |
7756 KB |
Output is correct |
3 |
Correct |
92 ms |
10688 KB |
Output is correct |
4 |
Correct |
102 ms |
12992 KB |
Output is correct |
5 |
Correct |
104 ms |
13248 KB |
Output is correct |
6 |
Correct |
103 ms |
12960 KB |
Output is correct |
7 |
Correct |
105 ms |
12988 KB |
Output is correct |
8 |
Correct |
102 ms |
12988 KB |
Output is correct |
9 |
Correct |
90 ms |
10684 KB |
Output is correct |
10 |
Correct |
99 ms |
12828 KB |
Output is correct |
11 |
Correct |
100 ms |
12912 KB |
Output is correct |
12 |
Correct |
90 ms |
10604 KB |
Output is correct |
13 |
Correct |
56 ms |
8132 KB |
Output is correct |
14 |
Correct |
94 ms |
10940 KB |
Output is correct |
15 |
Correct |
91 ms |
11188 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
53 ms |
7544 KB |
Output is correct |
18 |
Correct |
54 ms |
7628 KB |
Output is correct |
19 |
Correct |
92 ms |
10600 KB |
Output is correct |
20 |
Correct |
107 ms |
12912 KB |
Output is correct |
21 |
Correct |
101 ms |
12996 KB |
Output is correct |
22 |
Correct |
101 ms |
12912 KB |
Output is correct |