#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1100006;
#include "doll.h"
int sm[MAXN], add[MAXN], nxt[MAXN];
void create_circuit(int M, vector<int> A) {
vi C(M+1, -1), X, Y, gr;
for (int i = 1; i < (int) A.size(); ++i) {
gr.push_back(A[i]);
}
gr.push_back(0);
C[0] = A[0];
int n = 2;
while (n < (int)gr.size())
n<<=1;
int extra = n-(int)gr.size();
sm[1] = 0;
add[1] = 1;
// This is like radix sort (in case anyone is interested)
for (int j = 1; j < n; ++j) {
sm[j<<1] = sm[j];
sm[j<<1|1] = sm[j]+add[j];
add[j<<1] = add[j<<1|1] = add[j]<<1;
}
for (int j = 0, erased = 0; j < n; ++j) {
if (sm[n+j] < extra) erased++;
else nxt[sm[n+j]] = gr[j-erased];
}
sm[0] = 0;
add[0] = n>>1;
X.emplace_back(), Y.emplace_back();
for (int s = 0; s < (int) X.size(); ++s) {
if (add[s] == 1) {
X[s] = sm[s] < extra? -1 : nxt[sm[s]];
Y[s] = nxt[sm[s]+1];
continue;
}
if (sm[s]+add[s] <= extra) {
X[s] = -1;
} else {
X[s] = -X.size()-1;
sm[X.size()] = sm[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
Y[s] = -X.size()-1;
sm[X.size()] = sm[s]+add[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
5108 KB |
Output is correct |
3 |
Correct |
34 ms |
5932 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1484 KB |
Output is correct |
6 |
Correct |
51 ms |
7524 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
5108 KB |
Output is correct |
3 |
Correct |
34 ms |
5932 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1484 KB |
Output is correct |
6 |
Correct |
51 ms |
7524 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
56 ms |
8260 KB |
Output is correct |
9 |
Correct |
62 ms |
10732 KB |
Output is correct |
10 |
Correct |
91 ms |
13404 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
36 ms |
5108 KB |
Output is correct |
3 |
Correct |
34 ms |
5932 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
14 ms |
1484 KB |
Output is correct |
6 |
Correct |
51 ms |
7524 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
56 ms |
8260 KB |
Output is correct |
9 |
Correct |
62 ms |
10732 KB |
Output is correct |
10 |
Correct |
91 ms |
13404 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
90 ms |
13032 KB |
Output is correct |
15 |
Correct |
66 ms |
9856 KB |
Output is correct |
16 |
Correct |
86 ms |
12772 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
88 ms |
13148 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
48 ms |
7860 KB |
Output is correct |
3 |
Correct |
50 ms |
9556 KB |
Output is correct |
4 |
Correct |
73 ms |
12360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
48 ms |
7860 KB |
Output is correct |
3 |
Correct |
50 ms |
9556 KB |
Output is correct |
4 |
Correct |
73 ms |
12360 KB |
Output is correct |
5 |
Correct |
86 ms |
12636 KB |
Output is correct |
6 |
Correct |
82 ms |
12516 KB |
Output is correct |
7 |
Correct |
85 ms |
12524 KB |
Output is correct |
8 |
Correct |
76 ms |
12384 KB |
Output is correct |
9 |
Correct |
50 ms |
9572 KB |
Output is correct |
10 |
Correct |
81 ms |
12376 KB |
Output is correct |
11 |
Correct |
74 ms |
12384 KB |
Output is correct |
12 |
Correct |
54 ms |
9568 KB |
Output is correct |
13 |
Correct |
52 ms |
7868 KB |
Output is correct |
14 |
Correct |
57 ms |
9700 KB |
Output is correct |
15 |
Correct |
56 ms |
9836 KB |
Output is correct |
16 |
Correct |
3 ms |
588 KB |
Output is correct |
17 |
Correct |
51 ms |
7800 KB |
Output is correct |
18 |
Correct |
50 ms |
7844 KB |
Output is correct |
19 |
Correct |
52 ms |
9460 KB |
Output is correct |
20 |
Correct |
82 ms |
12380 KB |
Output is correct |
21 |
Correct |
103 ms |
12280 KB |
Output is correct |
22 |
Correct |
81 ms |
12380 KB |
Output is correct |