#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
4788 KB |
Output is correct |
3 |
Correct |
26 ms |
4404 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
35 ms |
5916 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
4788 KB |
Output is correct |
3 |
Correct |
26 ms |
4404 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
35 ms |
5916 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
44 ms |
7136 KB |
Output is correct |
9 |
Correct |
47 ms |
7556 KB |
Output is correct |
10 |
Correct |
70 ms |
9864 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
26 ms |
4788 KB |
Output is correct |
3 |
Correct |
26 ms |
4404 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
35 ms |
5916 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
44 ms |
7136 KB |
Output is correct |
9 |
Correct |
47 ms |
7556 KB |
Output is correct |
10 |
Correct |
70 ms |
9864 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
64 ms |
9384 KB |
Output is correct |
15 |
Correct |
41 ms |
6772 KB |
Output is correct |
16 |
Correct |
59 ms |
9152 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
64 ms |
9620 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
37 ms |
6364 KB |
Output is correct |
3 |
Correct |
38 ms |
6396 KB |
Output is correct |
4 |
Correct |
59 ms |
8592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
37 ms |
6364 KB |
Output is correct |
3 |
Correct |
38 ms |
6396 KB |
Output is correct |
4 |
Correct |
59 ms |
8592 KB |
Output is correct |
5 |
Correct |
60 ms |
9028 KB |
Output is correct |
6 |
Correct |
68 ms |
8864 KB |
Output is correct |
7 |
Correct |
59 ms |
8888 KB |
Output is correct |
8 |
Correct |
57 ms |
8756 KB |
Output is correct |
9 |
Correct |
35 ms |
6396 KB |
Output is correct |
10 |
Correct |
55 ms |
8704 KB |
Output is correct |
11 |
Correct |
54 ms |
8516 KB |
Output is correct |
12 |
Correct |
37 ms |
6412 KB |
Output is correct |
13 |
Correct |
38 ms |
6616 KB |
Output is correct |
14 |
Correct |
45 ms |
6632 KB |
Output is correct |
15 |
Correct |
39 ms |
6728 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
36 ms |
5712 KB |
Output is correct |
18 |
Correct |
36 ms |
6396 KB |
Output is correct |
19 |
Correct |
40 ms |
6392 KB |
Output is correct |
20 |
Correct |
55 ms |
8644 KB |
Output is correct |
21 |
Correct |
54 ms |
8508 KB |
Output is correct |
22 |
Correct |
55 ms |
8560 KB |
Output is correct |