# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922853 | boris_mihov | Minerals (JOI19_minerals) | C++17 | 68 ms | 60048 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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <random>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 86000 + 10;
const int INF = 1e9;
int n;
struct Material
{
int idx;
int l, r;
};
int with[MAXN];
int perm[MAXN];
bool isIn[MAXN];
std::vector <int> unique;
std::vector <int> second;
std::vector <int> secondCopy;
std::deque <Material> waitlist[MAXN];
std::mt19937 rng(69420);
int countDiff;
int query(int idx)
{
isIn[idx] ^= 1;
return countDiff = Query(perm[idx]);
}
void answer(int a, int b)
{
Answer(perm[a], perm[b]);
}
void Solve(int N)
{
n = N;
std::iota(perm + 1, perm + 1 + 2 * n, 1);
std::shuffle(perm + 1, perm + 1 + 2 * n, rng);
int last = 0;
for (int i = 1 ; i <= 2 * n ; ++i)
{
if (unique.size() < n && (second.size() == n || query(i) > last))
{
last++;
unique.push_back(i);
} else
{
waitlist[1].push_back({i, 1, (int)unique.size() - 1});
second.push_back(i);
}
}
assert(unique.size() == n);
assert(second.size() == n);
for (int bit = 0 ; (1 << bit) < n ; ++bit)
{
int cntIn = 0;
int cntOut = 0;
for (int i = 0 ; i < n ; ++i)
{
if (((i & (1 << bit)) > 0) != isIn[unique[i]])
{
query(unique[i]);
}
cntIn += isIn[unique[i]];
cntOut += !isIn[unique[i]];
}
for (int i = 0 ; i < n ; ++i)
{
if (cntIn == 0)
{
continue;
}
if (cntOut == 0)
{
with[second[i]] |= (1 << bit);
continue;
}
int curr = countDiff;
int next = query(second[i]);
if (curr == next)
{
cntIn--;
with[second[i]] |= (1 << bit);
} else
{
cntOut--;
}
}
}
for (int i = 0 ; i < n ; ++i)
{
answer(second[i], unique[with[second[i]]]);
}
}
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... |