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<bits/stdc++.h>
#include "doll.h"
using namespace std;
using ll = long long;
void create_circuit(int m, std::vector<int> arr) {
vector<int> c(m+1);
vector<int> x, y;
auto add = [&](int a, int b){
x.push_back(a), y.push_back(b);
return -(int)x.size();
};
auto tree = [&](auto& tree, vector<int> nxt) {
if (nxt.size() == 1) {
return nxt[0];
}
vector<int> odd, even;
for (int i = 0; i < (int)nxt.size(); i += 2) {
odd.push_back(nxt[i]);
even.push_back(nxt[i+1]);
}
int t1 = tree(tree, odd);
int t2 = tree(tree, even);
return add(t1, t2);
};
int n = arr.size();
vector<vector<int>> nxt(m+1);
arr.push_back(0);
for (int i = 0; i < n; i++) {
nxt[arr[i]].push_back(arr[i+1]);
}
for (int i = 1; i <= m; i++) {
if (nxt[i].empty()) {
c[i] = 0;
} else {
reverse(nxt[i].begin(), nxt[i].end());
while (__builtin_popcount(nxt[i].size()) > 1)
nxt[i].push_back(INT_MAX);
reverse(nxt[i].begin(), nxt[i].end());
int start = x.size();
c[i] = tree(tree, nxt[i]);
while (start < (int)x.size()) {
if (x[start] == INT_MAX)
x[start] = c[i];
if (y[start] == INT_MAX)
y[start] = c[i];
start++;
}
}
}
c[0] = arr[0];
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... |