#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ln '\n'
#define all(x) x.begin(), x.end()
template <class F, class S>
bool chmax(F &u, const S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
void create_circuit(int m, std::vector<int> A) {
int n = A.size(), x = (n + 1) / 2;
int lg = __lg(x);
if ( (1 << lg) < x ) ++lg;
vector <int> L(2 * n), R(2 * n);
int ct = 0;
auto build_tree = [&](auto build_tree, int v, int d) -> void{
chmax(ct, v);
L[v] = R[v] = -1;
if ( d == 0 ) return;
L[v] = v * 2, R[v] = v * 2 + 1;
build_tree(build_tree, v * 2, d - 1);
build_tree(build_tree, v * 2 + 1, d - 1);
};
build_tree(build_tree, 1, lg);
vector <int> C(m + 1, -1), X(ct), Y(ct);
C[0] = A[0];
vector <int> state(ct + 1);
auto dfs = [&](auto dfs, int v, int p) -> void{
state[v] ^= 1;
if ( v == ct && !state[v] ){ // last Vertex
Y[v - 1] = 0; return;
}
if ( L[v] == -1 ){ // leaf vertex
if ( state[v] > 0 ){
X[v - 1] = (p < n ? A[p] : -1);
} else Y[v - 1] = (p < n ? A[p] : -1);
dfs(dfs, 1, p + 1);
return;
}
X[v - 1] = -L[v];
Y[v - 1] = -R[v];
if ( state[v] ){
dfs(dfs, L[v], p);
} else dfs(dfs, R[v], p);
};
dfs(dfs, 1, 1);
{ // compressing
vector <int> is(ct + 1);
auto dfs = [&](auto dfs, int v) -> bool{
if ( L[v] == -1 ){ // leaf
return X[v] != -1 || Y[v] != -1;
}
bool x = dfs(dfs, L[v]) || dfs(dfs, R[v]);
if ( !x ) is[v] = 1;
return x;
};
//~ dfs(dfs, 1);
int cnt = 0;
map <int,int> id;
auto get = [&](int u){
if ( !id.count(u) ){
id[u] = ++cnt;
} return id[u];
};
vector <int> x, y;
auto trav = [&](auto trav, int v) -> int{
if ( is[v] ){
x.pb(-1), y.pb(-1);
return get(v);
}
int ret = get(v);
if ( L[v] == -1 ){ // leaf
x.pb(X[v - 1]), y.pb(Y[v - 1]);
} else{
x.pb(-get(L[v])), y.pb(-get(R[v]));
trav(trav, L[v]); trav(trav, R[v]);
}
return ret;
};
trav(trav, 1);
//~ for ( int i = 0; i <= m; i++ ){
//~ cout << i << " " << C[i] << ln;
//~ }
//~ for ( int i = 0; i < (int)id.size(); i++ ){
//~ cout << -(i + 1) << ' ' << x[i] << ln;
//~ cout << -(i + 1) << " " << y[i] << ln;
//~ }
answer(C, x, y);
}
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:84:8: warning: variable 'dfs' set but not used [-Wunused-but-set-variable]
84 | auto dfs = [&](auto dfs, int v) -> bool{
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |