This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
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 build2(vi &vec , int l = 0, int r = -1) {
if (r == -1) r = vec.size();
if (l == r - 1) return vec[inve(__builtin_ctz(vec.size()), l)];
int mid = l + r >> 1;
int me = cnt++;
X.pb(0), Y.pb(0);
int le = build2(vec , l , mid);
int re = build2(vec , mid , r);
X[me - 1] = le;
Y[me - 1] = re;
return -me;
}
void build(vi vec) {
//if (vec.empty()) return;
int sz = vec.size();
if(__builtin_popcount(sz) == 1) {
build2(vec);
return;
}
for (int i = 20; ~i; i--)
if (sz > (1 << i) - 1) {
vi local(vec.begin() , vec.begin() + (1 << i) - 1);
local.pb(-(cnt + (1 << i) - 1));
build2(local);
build(vi(vec.begin() + (1 << i) - 1 , vec.end()));
break;
}
}
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;
}
Compilation message (stderr)
doll.cpp: In function 'int build2(vi&, int, int)':
doll.cpp:28:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |