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"
#define pb(x) push_back(x)
using namespace std;
const int N = 4e5+5;
vector<int> adj[N], id;
int who[N], sw[N], S, XX[N], YY[N];
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 dfs(int l, int r, int rem, int root, vector<int>&values){
if (l == r){
if (r < rem)
return root;
return values[who[l]];
}
int nd = get_switch();
int mid = (l+r) >> 1;
XX[-nd] = dfs(l, mid, rem, root, values);
YY[-nd] = dfs(mid+1, r, rem, root, values);
return nd;
}
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;
id.clear();
for (int i = 0; i < pw; i++)
f(1, 0, pw/2, i), id.pb(i);
for (int i = 0; i < pw-sz; i++)
who[i] = pw;
sort(id.begin(), id.end(), [&](int x, int y){
return (who[x] < who[y]);
});
for (int i = 0; i < sz; i++)
who[id[i]] = i;
return dfs(0, pw-1, pw-sz, S-1, values);
}
void create_circuit(int M, vector<int> A) {
int N = A.size();
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);
vector<int> C(M + 1);
for (int i = 0; i <= M; ++i)
C[i] = get_root(adj[i]);
vector<int> X(-S), Y(-S);
for (int i = 1; i <= -S; i++)
X[i-1] = XX[i], Y[i-1] = YY[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... |