#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define pb push_back
#define all(x) x.begin(),x.end()
typedef vector<int> vi;
const int N = 2e5 + 10;
vi C , X ,Y, nx[N];
int n, cnt = 1;
inline int inve(int sz , int l) {
int res = 0;
rep(i , 0 , sz)
if (l & (1 << i))
res ^= (1 << (sz - 1 - i));
return res;
}
int build(int root, int lvl , int &g, int st = 0) {
if ((g >> lvl) & 1) {
g -= (1 << lvl);
return root;
}
if (lvl == 0) return -(N + st);
int me = cnt++;
X.pb(0);
Y.pb(0);
X[me - 1] = -build(root , lvl - 1, g , st);
Y[me - 1] = -build(root , lvl - 1, g , st + (1 << (lvl - 1)));
return me;
}
void build(vi vec) {
int z = 0;
while ((1 << z) < (int)vec.size()) z++;
int st = cnt;
int g = (1 << z) - vec.size();
build(cnt , z , g);
vi k;
rep(i , st - 1 , cnt - 1) {
if (X[i] >= N) k.pb(X[i] - N);
if (Y[i] >= N) k.pb(Y[i] - N);
}
auto cmp = [&](int a, int b) {
return inve(z , a) < inve(z , b);
};
sort(all(k) , cmp);
map<int , int> mp;
rep(i , 0 , k.size())
mp[k[i]] = i;
rep(i , st - 1, cnt - 1) {
if (X[i] >= N) X[i] = vec[mp[X[i] - N]];
if (Y[i] >= N) Y[i] = vec[mp[Y[i] - N]];
}
}
void create_circuit(int M, vi A) {
n = A.size();
A.pb(0);
rep(i , 0 , n)
nx[A[i]].pb(A[i + 1]);
C.resize(M + 1);
C[0] = A[0];
rep(i , 1 , M + 1) {
if (nx[i].empty())
C[i] = 0;
else if (nx[i].size() == 1) {
C[i] = nx[i][0];
}
else {
C[i] = -cnt;
build(nx[i]);
}
}
answer(C , X , Y);
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4996 KB |
Output is correct |
2 |
Correct |
45 ms |
8624 KB |
Output is correct |
3 |
Correct |
40 ms |
8324 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
18 ms |
6092 KB |
Output is correct |
6 |
Correct |
62 ms |
10200 KB |
Output is correct |
7 |
Correct |
5 ms |
5028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4996 KB |
Output is correct |
2 |
Correct |
45 ms |
8624 KB |
Output is correct |
3 |
Correct |
40 ms |
8324 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
18 ms |
6092 KB |
Output is correct |
6 |
Correct |
62 ms |
10200 KB |
Output is correct |
7 |
Correct |
5 ms |
5028 KB |
Output is correct |
8 |
Correct |
85 ms |
11108 KB |
Output is correct |
9 |
Correct |
80 ms |
11544 KB |
Output is correct |
10 |
Correct |
160 ms |
14640 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
6 ms |
4940 KB |
Output is correct |
13 |
Correct |
6 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4996 KB |
Output is correct |
2 |
Correct |
45 ms |
8624 KB |
Output is correct |
3 |
Correct |
40 ms |
8324 KB |
Output is correct |
4 |
Correct |
4 ms |
4940 KB |
Output is correct |
5 |
Correct |
18 ms |
6092 KB |
Output is correct |
6 |
Correct |
62 ms |
10200 KB |
Output is correct |
7 |
Correct |
5 ms |
5028 KB |
Output is correct |
8 |
Correct |
85 ms |
11108 KB |
Output is correct |
9 |
Correct |
80 ms |
11544 KB |
Output is correct |
10 |
Correct |
160 ms |
14640 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
6 ms |
4940 KB |
Output is correct |
13 |
Correct |
6 ms |
4940 KB |
Output is correct |
14 |
Correct |
140 ms |
16468 KB |
Output is correct |
15 |
Correct |
105 ms |
10828 KB |
Output is correct |
16 |
Correct |
158 ms |
13664 KB |
Output is correct |
17 |
Correct |
6 ms |
4992 KB |
Output is correct |
18 |
Correct |
5 ms |
4940 KB |
Output is correct |
19 |
Correct |
6 ms |
4940 KB |
Output is correct |
20 |
Correct |
157 ms |
15200 KB |
Output is correct |
21 |
Correct |
4 ms |
4940 KB |
Output is correct |
22 |
Correct |
6 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4940 KB |
Output is correct |
2 |
Correct |
5 ms |
4940 KB |
Output is correct |
3 |
Correct |
5 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4984 KB |
Output is correct |
7 |
Correct |
5 ms |
4900 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4940 KB |
Output is correct |
2 |
Correct |
494 ms |
15360 KB |
Output is correct |
3 |
Correct |
504 ms |
14876 KB |
Output is correct |
4 |
Correct |
658 ms |
20100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4940 KB |
Output is correct |
2 |
Correct |
494 ms |
15360 KB |
Output is correct |
3 |
Correct |
504 ms |
14876 KB |
Output is correct |
4 |
Correct |
658 ms |
20100 KB |
Output is correct |
5 |
Partially correct |
142 ms |
16824 KB |
Output is partially correct |
6 |
Partially correct |
176 ms |
16500 KB |
Output is partially correct |
7 |
Partially correct |
168 ms |
16596 KB |
Output is partially correct |
8 |
Partially correct |
190 ms |
15840 KB |
Output is partially correct |
9 |
Partially correct |
508 ms |
13300 KB |
Output is partially correct |
10 |
Partially correct |
541 ms |
17044 KB |
Output is partially correct |
11 |
Partially correct |
323 ms |
14052 KB |
Output is partially correct |
12 |
Partially correct |
208 ms |
11392 KB |
Output is partially correct |
13 |
Partially correct |
106 ms |
11768 KB |
Output is partially correct |
14 |
Partially correct |
97 ms |
11832 KB |
Output is partially correct |
15 |
Partially correct |
115 ms |
11988 KB |
Output is partially correct |
16 |
Partially correct |
10 ms |
5196 KB |
Output is partially correct |
17 |
Partially correct |
249 ms |
10168 KB |
Output is partially correct |
18 |
Partially correct |
200 ms |
10952 KB |
Output is partially correct |
19 |
Partially correct |
181 ms |
11172 KB |
Output is partially correct |
20 |
Partially correct |
234 ms |
14160 KB |
Output is partially correct |
21 |
Partially correct |
322 ms |
14096 KB |
Output is partially correct |
22 |
Partially correct |
312 ms |
13732 KB |
Output is partially correct |