#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5+1;
int m, n, need, nodes, c[N], l[N], r[N], x[N], y[N];
vector<int> a;
vector<int> ls[N];
bool state[N], leaf_l[N], leaf_r[N];
void dfs(int i, int val) {
bool org = state[i];
state[i] ^= 1;
if(org) {
if(r[i] == -1) {
// cout << i << " r" << ' ' << val << endl;
y[i] = val;
} else dfs(r[i], val);
} else {
if(l[i] == -1) {
// cout << i << " l" << ' ' << val << endl;
x[i] = val;
} else dfs(l[i], val);
}
}
void create_circuit(int _m, vector<int> _a) {
m = _m, a = _a;
n = a.size();
a.insert(a.begin(), 0);
a.push_back(0);
for(int i = 0; i < (int) a.size() - 1; i++) ls[a[i]].push_back(a[i+1]);
for(int i = 0; i <= m; i++) {
if(ls[i].empty()) c[i] = 1;
else if(ls[i].size() == 1) c[i] = ls[i][0];
else c[i] = -1;
}
for(int i = 0; i < (int) a.size() - 1; i++) need += ls[a[i]].size() > 1;
int lgn = log2(need);
for(int i = 1; i <= lgn + 1; i++) {
if(i <= lgn) l[i] = i+1, x[i] = -l[i];
else {
l[i] = 1;
r[i] = (need % 2 ? -1 : 1);
leaf_l[i] = leaf_r[i] = 1;
x[i] = y[i] = -1;
}
}
nodes += log2(need) + 1;
for(int i = 1; i <= lgn; i++) {
int sz = 1 << (lgn + 1 - i);
if(need & sz) {
r[i] = nodes + 1;
y[i] = -r[i];
for(int t = 1; t < sz; t++) {
if(t < sz / 2) {
l[nodes + t] = nodes + (t << 1);
r[nodes + t] = nodes + (t << 1 | 1);
x[nodes + t] = -l[nodes + t];
y[nodes + t] = -r[nodes + t];
} else {
leaf_l[nodes + t] = leaf_r[nodes + t] = 1;
l[nodes + t] = r[nodes + t] = -1;
}
}
nodes += sz - 1;
} else {
r[i] = 1;
y[i] = -1;
leaf_r[i] = 1;
}
// cout << i << ' ' << nodes << ' ' << sz << ' ' << l[i] << ' ' << leaf_l[i] << ' ' << r[i] << ' ' << leaf_r[i] << endl;
}
// for(int i = 1; i <= nodes; i++) {
// cout << i << ' ' << l[i] << ' ' << r[i] << ' ' << leaf_l[i] << ' ' << leaf_r[i] << endl;
// }
//
for(int i = 0; i < (int) a.size() - 1; i++) {
if(ls[a[i]].size() <= 1) continue;
dfs(1, a[i+1]);
}
vector<int> C, X, Y;
for(int i = 0; i <= m; i++) C.push_back(c[i]);
for(int i = 1; i <= nodes; i++) X.push_back(x[i]), Y.push_back(y[i]);
// for(int i = 1; i <= nodes; i++) cout << -i << ' ' << x[i] << ' ' << y[i] << endl;
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
52 ms |
14180 KB |
Output is correct |
3 |
Correct |
41 ms |
13512 KB |
Output is correct |
4 |
Correct |
8 ms |
9676 KB |
Output is correct |
5 |
Correct |
20 ms |
11332 KB |
Output is correct |
6 |
Correct |
75 ms |
15472 KB |
Output is correct |
7 |
Correct |
9 ms |
9656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
52 ms |
14180 KB |
Output is correct |
3 |
Correct |
41 ms |
13512 KB |
Output is correct |
4 |
Correct |
8 ms |
9676 KB |
Output is correct |
5 |
Correct |
20 ms |
11332 KB |
Output is correct |
6 |
Correct |
75 ms |
15472 KB |
Output is correct |
7 |
Correct |
9 ms |
9656 KB |
Output is correct |
8 |
Correct |
117 ms |
21336 KB |
Output is correct |
9 |
Correct |
100 ms |
20508 KB |
Output is correct |
10 |
Correct |
181 ms |
25656 KB |
Output is correct |
11 |
Correct |
7 ms |
9700 KB |
Output is correct |
12 |
Correct |
10 ms |
9676 KB |
Output is correct |
13 |
Correct |
10 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9676 KB |
Output is correct |
2 |
Correct |
52 ms |
14180 KB |
Output is correct |
3 |
Correct |
41 ms |
13512 KB |
Output is correct |
4 |
Correct |
8 ms |
9676 KB |
Output is correct |
5 |
Correct |
20 ms |
11332 KB |
Output is correct |
6 |
Correct |
75 ms |
15472 KB |
Output is correct |
7 |
Correct |
9 ms |
9656 KB |
Output is correct |
8 |
Correct |
117 ms |
21336 KB |
Output is correct |
9 |
Correct |
100 ms |
20508 KB |
Output is correct |
10 |
Correct |
181 ms |
25656 KB |
Output is correct |
11 |
Correct |
7 ms |
9700 KB |
Output is correct |
12 |
Correct |
10 ms |
9676 KB |
Output is correct |
13 |
Correct |
10 ms |
9684 KB |
Output is correct |
14 |
Correct |
200 ms |
24188 KB |
Output is correct |
15 |
Correct |
123 ms |
19520 KB |
Output is correct |
16 |
Correct |
149 ms |
24188 KB |
Output is correct |
17 |
Correct |
8 ms |
9676 KB |
Output is correct |
18 |
Correct |
8 ms |
9676 KB |
Output is correct |
19 |
Correct |
9 ms |
9676 KB |
Output is correct |
20 |
Correct |
169 ms |
24320 KB |
Output is correct |
21 |
Correct |
7 ms |
9676 KB |
Output is correct |
22 |
Correct |
7 ms |
9676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9652 KB |
Output is correct |
2 |
Correct |
7 ms |
9676 KB |
Output is correct |
3 |
Correct |
9 ms |
9724 KB |
Output is correct |
4 |
Correct |
7 ms |
9656 KB |
Output is correct |
5 |
Correct |
7 ms |
9676 KB |
Output is correct |
6 |
Correct |
7 ms |
9676 KB |
Output is correct |
7 |
Correct |
7 ms |
9624 KB |
Output is correct |
8 |
Correct |
8 ms |
9720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9672 KB |
Output is correct |
2 |
Correct |
79 ms |
17640 KB |
Output is correct |
3 |
Correct |
91 ms |
17172 KB |
Output is correct |
4 |
Correct |
128 ms |
21080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9672 KB |
Output is correct |
2 |
Correct |
79 ms |
17640 KB |
Output is correct |
3 |
Correct |
91 ms |
17172 KB |
Output is correct |
4 |
Correct |
128 ms |
21080 KB |
Output is correct |
5 |
Correct |
152 ms |
24688 KB |
Output is correct |
6 |
Correct |
188 ms |
22944 KB |
Output is correct |
7 |
Correct |
149 ms |
23088 KB |
Output is correct |
8 |
Correct |
145 ms |
23556 KB |
Output is correct |
9 |
Correct |
92 ms |
17296 KB |
Output is correct |
10 |
Correct |
125 ms |
22200 KB |
Output is correct |
11 |
Correct |
120 ms |
22988 KB |
Output is correct |
12 |
Correct |
105 ms |
18760 KB |
Output is correct |
13 |
Correct |
92 ms |
19384 KB |
Output is correct |
14 |
Correct |
90 ms |
18516 KB |
Output is correct |
15 |
Correct |
106 ms |
18828 KB |
Output is correct |
16 |
Correct |
13 ms |
9932 KB |
Output is correct |
17 |
Correct |
84 ms |
18900 KB |
Output is correct |
18 |
Correct |
83 ms |
17508 KB |
Output is correct |
19 |
Correct |
76 ms |
17644 KB |
Output is correct |
20 |
Correct |
130 ms |
22712 KB |
Output is correct |
21 |
Correct |
125 ms |
21736 KB |
Output is correct |
22 |
Correct |
121 ms |
21484 KB |
Output is correct |