# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
487300 | Rainbowbunny | Minerals (JOI19_minerals) | C++17 | 49 ms | 3272 KiB |
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 "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 45005;
bool In[2 * MAXN];
int lst = 0;
bool query(int i) {
In[i] ^= 1;
int cur = Query(i);
bool ans = cur != lst;
return lst = cur, ans;
}
int idx[2 * MAXN];
vector<int> A, B;
vector<pair<int, int>> pairs;
constexpr double rat = 1 / 2.56; //ternary
void dfs(int l, int r, const vector<int>& b, bool is_on) {
if(l == r) {
assert(b.size() == 1);
pairs.emplace_back(idx[A[l]], idx[b[0]]);
return;
}
int m = l + (r - l) * rat;
for(int i = l; i <= m; i++) query(idx[A[i]]);
vector<int> lf, rg;
for(int id: b) {
if(lf.size() == m - l + 1) rg.push_back(id);
else if(rg.size() == r - m) lf.push_back(id);
else (query(idx[id]) == is_on ? lf : rg).push_back(id);
}
dfs(l, m, lf, is_on ^ 1);
if(m < r) dfs(m + 1, r, rg, is_on);
}
void Solve(int n) {
mt19937 rng(233);
iota(idx + 1, idx + (2 * n) + 1, 1);
shuffle(idx + 1, idx + (2 * n) + 1, rng);
for(int i = 1; i <= 2 * n; i++) (query(idx[i]) ? A : B).push_back(i);
dfs(0, n - 1, B, 1);
assert(pairs.size() == n);
for(auto& x: pairs) Answer(x.first, x.second);
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |