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 "messy.h"
using namespace std;
string query;
void rec_build(int l, int r) {
if (r - l <= 1) { return; }
int m = l + (r - l) / 2;
for (int i = m; i < r; ++i) {
query[i] = '1';
add_element(query);
query[i] = '0';
}
for (int i = l; i < m; ++i) {
query[i] = '1';
}
rec_build(m, r);
for (int i = l; i < m; ++i) {
query[i] = '0';
}
for (int i = m; i < r; ++i) {
query[i] = '1';
}
rec_build(l, m);
for (int i = m; i < r; ++i) {
query[i] = '0';
}
}
void rec_find(vector<int>& rest, int bit, vector<int>& p) {
if ((int)rest.size() <= 1) { return; }
/*cerr << "rest:\n";
for (const int& i : rest) {
cerr << i << ' ';
}
cerr << "\nbit: " << bit << '\n';*/
assert(bit >= 0);
vector<int> on, off;
for (const int& i : rest) {
query[i] = '1';
if (check_element(query)) {
p[i] |= (1 << bit);
on.emplace_back(i);
} else {
off.emplace_back(i);
}
query[i] = '0';
}
for (const int& i : off) {
query[i] = '1';
}
rec_find(on, bit - 1, p);
for (const int& i : off) {
query[i] = '0';
}
for (const int& i : on) {
query[i] = '1';
}
rec_find(off, bit - 1, p);
for (const int& i : on) {
query[i] = '0';
}
}
vector<int> restore_permutation(int n, int w, int r) {
vector<int> p(n);
query = string(n, '0');
rec_build(0, n);
compile_set();
int lg = 0;
while ((1 << lg) < n) {
++lg;
}
vector<int> rest(n);
iota(rest.begin(), rest.end(), 0);
rec_find(rest, lg - 1, p);
return p;
}
# | 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... |