이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
#define ar array
typedef int64_t ll;
typedef int32_t ii;
//~ #define int ll
bool check(vector<int> c, vector<int> x, vector<int> y, vector<int> b){
int u = 0, sz = x.size();
vector<int> sw(sz), a;
do{
if(u > 0){
a.push_back(u);
}
if(u >= 0){
u = c[u];
continue;
}
int p = u;
if(!sw[-u - 1]){
u = x[-u - 1];
} else {
u = y[-u - 1];
}
sw[-p - 1] ^= 1;
}while(u);
//~ for(auto x : a) cout<<x<<" ";
//~ cout<<"\n";
//~ for(auto x : b) cout<<x<<" ";
//~ cout<<"\n";
for(int i=0;i<sz;i++){
if(sw[i]) return false;
}
if(a != b) return false;
return true;
};
void create_circuit(ii m, vector<ii> a){
a.push_back(0);
int n = a.size();
int sz = 1;
while(sz <= n) sz <<= 1;
vector<int> used(sz * 2);
function<void(int, int, int)> dfs = [&](int lx, int rx, int x){
if(rx + n <= sz){
return;
}
used[x] = 1;
if(lx == rx){
return;
}
int m = (lx + rx) >> 1;
dfs(lx, m, x << 1);
dfs(m + 1, rx, x << 1 | 1);
};
dfs(1, sz, 1);
vector<int> sw(sz * 2), pos(sz);
for(int i=0;i<sz;i++){
function<void(int, int, int)> go = [&](int x, int lx, int rx){
if(lx == rx){
pos[lx] = i;
return;
}
int m = (lx + rx) >> 1;
if(sw[x]) go(x << 1 | 1, m + 1, rx);
else go(x << 1, lx, m);
sw[x] ^= 1;
};
go(1, 0, sz - 1);
}
int last = 0;
vector<int> id;
for(int i=0;i<sz;i++){
if(used[i]){
used[i] = -(++last);
id.push_back(i);
} else {
used[i] = -1;
}
}
fill(used.begin() + sz, used.end(), -1);
vector<int> p(n);
iota(p.begin(), p.end(), sz - n);
sort(p.begin(), p.end(), [&](int i, int j){
return pos[i] < pos[j];
});
for(int i=0;i<n;i++){
used[sz + p[i]] = a[i];
}
//~ assert(last <= n - 1 + __lg(n - 1));
//~ assert(last <= 2 * (n - 1));
vector<int> c(m + 1, -1), x(last), y(last);
for(int i=0;i<last;i++){
x[i] = used[id[i] << 1];
y[i] = used[id[i] << 1 | 1];
}
a.pop_back();
assert(check(c, x, y, a));
answer(c, x, y);
}
# | 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... |