이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include "bits/stdc++.h"
#define pb(x) push_back(x)
using namespace std;
const int N = 4e5+5;
vector<int> X, Y;
vector<int> adj[N];
int who[N], sw[N], S;
void f(int nd, int pos, int pw, int id){
if (!pw){
who[pos] = id;
return;
}
sw[nd] ^= 1;
if (sw[nd])
f(nd*2, pos, pw/2, id);
else
f(nd*2+1, pos+pw, pw/2, id);
}
int get_switch(){
return --S;
}
int get_root(vector<int> &values){
int sz = values.size();
if (sz == 0)
return 0;
if (sz == 1)
return values[0];
int pw = 1;
while (pw < sz) pw *= 2;
for (int i = 0; i < pw; i++)
f(1, 0, pw/2, i);
int root = get_switch();
int to_the_root = pw - sz;
for (int i = 1; i < pw / 2; i++){
X.push_back(get_switch());
Y.push_back(get_switch());
}
for (int i = 0; i < pw / 2; i++){
int l = i * 2;
int r = i * 2 + 1;
if (who[l] < to_the_root) X.push_back(root);
else X.push_back(values[who[l] - to_the_root]);
if (who[r] < to_the_root) Y.push_back(root);
else Y.push_back(values[who[r] - to_the_root]);
}
return root;
}
void create_circuit(int M, vector<int> A) {
vector<int> C(M + 1);
int N = A.size();
if (N == 16 and 1 == 0){
A.push_back(0);
int one_root = get_root(A);
for (int i = 0; i <= M; ++i)
C[i] = one_root;
}
else{
adj[0].pb(A[0]);
for (int i = 0; i < N - 1; i++)
adj[A[i]].pb(A[i+1]);
adj[A[N-1]].pb(0);
for (int i = 0; i <= M; ++i)
C[i] = get_root(adj[i]);
}
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... |