#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
vector<int> C;
vector<int> X, Y;
int add_switch(const int x = kInf, const int y = kInf) {
X.push_back(x);
Y.push_back(y);
return -((int)X.size());
}
int calc_elements(const int n) {
const int h = 32 - __builtin_clz(n) - (__builtin_popcount(n) == 1);
return (1 << h);
}
void create_circuit(int m, std::vector<int> A) {
C.resize(m + 1, -1);
A.push_back(0);
const int n = A.size();
const int elems = calc_elements(n);
const int unused = elems - n;
vector<pair<int, int>> trigger_places(elems, {-1, -1});
function<void(int, int, int, int, int)> dfs = [&](const int x, const int l, const int r, const int depth, int path) {
const int mid = (l + r) / 2;
//left child
if (mid < unused) {
X[x] = -1;
} else if (l == mid) {
X[x] = path;
trigger_places[path] = {x, 0};
} else {
X[x] = add_switch();
dfs(-X[x] - 1, l, mid, depth + 1, path);
}
//right child
path += (1 << depth);
if (mid + 1 == r) {
Y[x] = path;
trigger_places[path] = {x, 1};
} else {
Y[x] = add_switch();
dfs(-Y[x] - 1, mid + 1, r, depth + 1, path);
}
};
add_switch();
dfs(0, 0, elems - 1, 0, 0);
for (int i = 0, j = 0; i < elems; i++) {
if (trigger_places[i] == make_pair(-1, -1)) continue;
const auto [s, dir] = trigger_places[i];
(dir == 0 ? X[s] : Y[s]) = A[j];
j++;
}
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
4816 KB |
Output is correct |
3 |
Correct |
24 ms |
4404 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
5912 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
4816 KB |
Output is correct |
3 |
Correct |
24 ms |
4404 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
5912 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
60 ms |
7164 KB |
Output is correct |
9 |
Correct |
45 ms |
7648 KB |
Output is correct |
10 |
Correct |
68 ms |
9884 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
46 ms |
4816 KB |
Output is correct |
3 |
Correct |
24 ms |
4404 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
5912 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
60 ms |
7164 KB |
Output is correct |
9 |
Correct |
45 ms |
7648 KB |
Output is correct |
10 |
Correct |
68 ms |
9884 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
66 ms |
9404 KB |
Output is correct |
15 |
Correct |
41 ms |
6884 KB |
Output is correct |
16 |
Correct |
66 ms |
9104 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
63 ms |
9624 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
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 |
51 ms |
6360 KB |
Output is correct |
3 |
Correct |
35 ms |
6396 KB |
Output is correct |
4 |
Correct |
56 ms |
8516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
51 ms |
6360 KB |
Output is correct |
3 |
Correct |
35 ms |
6396 KB |
Output is correct |
4 |
Correct |
56 ms |
8516 KB |
Output is correct |
5 |
Correct |
79 ms |
9004 KB |
Output is correct |
6 |
Correct |
58 ms |
8876 KB |
Output is correct |
7 |
Correct |
59 ms |
8884 KB |
Output is correct |
8 |
Correct |
57 ms |
8772 KB |
Output is correct |
9 |
Correct |
38 ms |
6396 KB |
Output is correct |
10 |
Correct |
56 ms |
8644 KB |
Output is correct |
11 |
Correct |
55 ms |
8508 KB |
Output is correct |
12 |
Correct |
37 ms |
6496 KB |
Output is correct |
13 |
Correct |
41 ms |
6628 KB |
Output is correct |
14 |
Correct |
38 ms |
6628 KB |
Output is correct |
15 |
Correct |
39 ms |
6780 KB |
Output is correct |
16 |
Correct |
2 ms |
536 KB |
Output is correct |
17 |
Correct |
37 ms |
5688 KB |
Output is correct |
18 |
Correct |
42 ms |
6488 KB |
Output is correct |
19 |
Correct |
42 ms |
6412 KB |
Output is correct |
20 |
Correct |
56 ms |
8644 KB |
Output is correct |
21 |
Correct |
55 ms |
8508 KB |
Output is correct |
22 |
Correct |
59 ms |
8644 KB |
Output is correct |