#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
int numNode, skiped;
vector<int> a, c, nxt[2], state, nodeInd;
vector<bool> mark;
void init(int id, int l, int r){
if (l + 1 == r){
mark[id] = (a[l] == -1 && a[r] == -1);
return;
}
int mid = (l + r) >> 1;
init(id << 1, l, mid);
init(id << 1 | 1, mid + 1, r);
mark[id] = mark[id << 1] && mark[id << 1 | 1];
}
void build(int id, int l, int r){
if (mark[id]){
skiped += r - l + 1;
return;
}
nodeInd[id] = ++numNode;
if (l + 1 == r)
return;
int mid = (l + r) >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
nxt[0][nodeInd[id] - 1] = mark[id << 1]? -1 : -nodeInd[id << 1];
nxt[1][nodeInd[id] - 1] = mark[id << 1 | 1]? -1 : -nodeInd[id << 1 | 1];
}
void create_circuit(int m, vector<int> _a) {
a = _a;
a.push_back(0);
reverse(a.begin(), a.end());
int n = 1;
while (n < (int) a.size())
n *= 2;
while ((int) a.size() < n)
a.push_back(-1);
reverse(a.begin(), a.end());
c.assign(m + 1, -1);
mark.assign(n, 0);
nodeInd.assign(n, 0);
nxt[0].assign(n, 0);
nxt[1].assign(n, 0);
state.assign(n, 0);
init(1, 0, n - 1);
build(1, 0, n - 1);
nxt[0].resize(numNode);
nxt[1].resize(numNode);
state.resize(numNode);
for(int i = skiped; i < n; i++){
int ind = a[i], cur = 1;
while (nxt[state[cur - 1]][cur - 1] < 0){
int tmp = -nxt[state[cur - 1]][cur - 1];
state[cur - 1] ^= 1;
cur = tmp;
}
nxt[state[cur - 1]][cur - 1] = ind;
state[cur - 1] ^= 1;
}
assert(*max_element(state.begin(), state.end()) == 0);
answer(c, nxt[0], nxt[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
6088 KB |
Output is correct |
3 |
Correct |
55 ms |
5904 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1384 KB |
Output is correct |
6 |
Correct |
87 ms |
7592 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
6088 KB |
Output is correct |
3 |
Correct |
55 ms |
5904 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1384 KB |
Output is correct |
6 |
Correct |
87 ms |
7592 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
108 ms |
10664 KB |
Output is correct |
9 |
Correct |
112 ms |
11168 KB |
Output is correct |
10 |
Correct |
168 ms |
13520 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
6088 KB |
Output is correct |
3 |
Correct |
55 ms |
5904 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1384 KB |
Output is correct |
6 |
Correct |
87 ms |
7592 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
108 ms |
10664 KB |
Output is correct |
9 |
Correct |
112 ms |
11168 KB |
Output is correct |
10 |
Correct |
168 ms |
13520 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
184 ms |
12972 KB |
Output is correct |
15 |
Correct |
114 ms |
10148 KB |
Output is correct |
16 |
Correct |
175 ms |
12688 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
158 ms |
13220 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
115 ms |
9124 KB |
Output is correct |
3 |
Correct |
108 ms |
9120 KB |
Output is correct |
4 |
Correct |
197 ms |
11284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
115 ms |
9124 KB |
Output is correct |
3 |
Correct |
108 ms |
9120 KB |
Output is correct |
4 |
Correct |
197 ms |
11284 KB |
Output is correct |
5 |
Correct |
165 ms |
12580 KB |
Output is correct |
6 |
Correct |
178 ms |
12316 KB |
Output is correct |
7 |
Correct |
154 ms |
12324 KB |
Output is correct |
8 |
Correct |
220 ms |
12056 KB |
Output is correct |
9 |
Correct |
108 ms |
9192 KB |
Output is correct |
10 |
Correct |
155 ms |
11912 KB |
Output is correct |
11 |
Correct |
172 ms |
11644 KB |
Output is correct |
12 |
Correct |
99 ms |
9484 KB |
Output is correct |
13 |
Correct |
106 ms |
9788 KB |
Output is correct |
14 |
Correct |
120 ms |
9900 KB |
Output is correct |
15 |
Correct |
105 ms |
10044 KB |
Output is correct |
16 |
Correct |
3 ms |
484 KB |
Output is correct |
17 |
Correct |
110 ms |
6856 KB |
Output is correct |
18 |
Correct |
124 ms |
9440 KB |
Output is correct |
19 |
Correct |
103 ms |
9436 KB |
Output is correct |
20 |
Correct |
158 ms |
11808 KB |
Output is correct |
21 |
Correct |
157 ms |
11536 KB |
Output is correct |
22 |
Correct |
156 ms |
11672 KB |
Output is correct |