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 "interactive.h"
#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;
template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;
vector<int> guess(int N) {
vector<int> ans(N);
ans[0] = ask(1);
const auto calc = [&](vector<int> pos) -> std::set<int> {
if (pos.empty()) {
return {};
}
for (auto& x : pos) {
x += 1;
}
std::map<int, int> count;
for (const int x : get_pairwise_xor(pos)) {
count[x] -= 1;
}
pos.push_back(1);
for (const int x : get_pairwise_xor(pos)) {
count[x] += 1;
}
std::set<int> ret;
for (const auto& [x, c] : count) {
if (c - (x == 0) > 0) {
ret.insert(x ^ ans[0]);
}
}
return ret;
};
const int LOG = 7;
array<std::set<int>, LOG> set = {};
for (int k = 0; k < LOG; ++k) {
vector<int> pos;
for (int i = 0; i < N; ++i) {
if (i >> k & 1) {
pos.push_back(i);
}
}
set[k] = calc(pos);
}
for (int i = 1; i < N; ++i) {
std::set<int> add, del;
for (int k = 0; k < LOG; ++k) {
if (i >> k & 1) {
if (add.empty()) {
add = set[k];
} else {
std::set<int> next;
for (const int x : set[k]) {
if (add.find(x) != add.end()) {
next.insert(x);
}
}
add = std::move(next);
}
} else {
for (const int x : set[k]) {
del.insert(x);
}
}
}
for (const int x : del) {
add.erase(x);
}
ans[i] = *add.begin();
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |