#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int S = 0;
vector<int> X, Y;
int create_switch(int L, int R) {
X.push_back(L);
Y.push_back(R);
S++;
return -S;
}
int build(int l, int r, vector<int> a, vector<int> p) {
if (a.empty()) {
return -1;
}
if (l == r) {
return a[0];
}
int mid = (l + r) / 2;
int m = (int)a.size();
vector<int> la, lp, ra, rp;
for (int i = 0; i < m; i++) {
if (p[i] <= mid) {
la.push_back(a[i]);
lp.push_back(p[i]);
} else {
ra.push_back(a[i]);
rp.push_back(p[i]);
}
}
return create_switch(build(l, mid, la, lp),
build(mid + 1, r, ra, rp));
}
void create_circuit(int M, vector<int> A) {
int N = (int)A.size();
vector<int> C(M + 1);
C[0] = A[0];
A.erase(A.begin());
A.push_back(0);
create_switch(-1, -1);
int mxpw = 0;
while ((1 << mxpw) < N) mxpw++;
vector<int> p;
for (int i = 0; i < N; i++) {
int x = (1 << mxpw) - 1 - i;
p.push_back(x);
}
auto rev = [&](int x) -> int {
int res = 0;
for (int i = 0; i < mxpw; i++) {
res *= 2;
if (x >> i & 1) res++;
}
return res;
};
sort(p.begin(), p.end(), [&](int a, int b) {
return rev(a) < rev(b);
});
// cout << '{';
// for (int c : A)
// cout << c << ' ';
// cout << '}';
// cout << '\n';
// cout << '{';
// for (int c : p)
// cout << c << ' ';
// cout << '}';
// cout << '\n';
int root;
root = build(0, (1 << mxpw) - 1, A, p);
Y[0] = root;
for (int i = 1; i <= M; i++) C[i] = root;
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
81 ms |
5484 KB |
Output is correct |
3 |
Correct |
77 ms |
5832 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
110 ms |
8168 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
81 ms |
5484 KB |
Output is correct |
3 |
Correct |
77 ms |
5832 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
110 ms |
8168 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
179 ms |
9284 KB |
Output is correct |
9 |
Correct |
157 ms |
11704 KB |
Output is correct |
10 |
Correct |
218 ms |
14928 KB |
Output is correct |
11 |
Correct |
0 ms |
348 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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
81 ms |
5484 KB |
Output is correct |
3 |
Correct |
77 ms |
5832 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1372 KB |
Output is correct |
6 |
Correct |
110 ms |
8168 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
179 ms |
9284 KB |
Output is correct |
9 |
Correct |
157 ms |
11704 KB |
Output is correct |
10 |
Correct |
218 ms |
14928 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
218 ms |
14844 KB |
Output is correct |
15 |
Correct |
163 ms |
11100 KB |
Output is correct |
16 |
Correct |
278 ms |
14564 KB |
Output is correct |
17 |
Correct |
1 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 |
245 ms |
14796 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
168 ms |
8888 KB |
Output is correct |
3 |
Correct |
154 ms |
10948 KB |
Output is correct |
4 |
Correct |
206 ms |
14136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
168 ms |
8888 KB |
Output is correct |
3 |
Correct |
154 ms |
10948 KB |
Output is correct |
4 |
Correct |
206 ms |
14136 KB |
Output is correct |
5 |
Correct |
214 ms |
14280 KB |
Output is correct |
6 |
Correct |
214 ms |
14020 KB |
Output is correct |
7 |
Correct |
213 ms |
14088 KB |
Output is correct |
8 |
Correct |
210 ms |
13964 KB |
Output is correct |
9 |
Correct |
162 ms |
10804 KB |
Output is correct |
10 |
Correct |
268 ms |
13964 KB |
Output is correct |
11 |
Correct |
205 ms |
14020 KB |
Output is correct |
12 |
Correct |
156 ms |
10948 KB |
Output is correct |
13 |
Correct |
189 ms |
8772 KB |
Output is correct |
14 |
Correct |
152 ms |
11028 KB |
Output is correct |
15 |
Correct |
152 ms |
10952 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
131 ms |
8884 KB |
Output is correct |
18 |
Correct |
174 ms |
8776 KB |
Output is correct |
19 |
Correct |
148 ms |
10948 KB |
Output is correct |
20 |
Correct |
207 ms |
14024 KB |
Output is correct |
21 |
Correct |
216 ms |
13940 KB |
Output is correct |
22 |
Correct |
221 ms |
14020 KB |
Output is correct |