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;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct RNG {
int operator () (int n) {
return rnd(n);
}
};
void solve(vector<int> u, vector<int> v, int f) {
if(u.empty()) return;
if(u.size() == 1) {
Answer(u.back(), v.back());
return;
}
random_shuffle(u.begin(), u.end(), RNG());
random_shuffle(v.begin(), v.end(), RNG());
int mid, last;
if(f) {
// mid = ((int)u.size() + 1) >> 1;
mid = 3 * u.size() / 5;
if(mid == u.size()) mid--;
for(int i = mid; i < v.size(); i++) {
last = Query(v[i]);
}
} else {
// mid = u.size() >> 1;
mid = 2 * u.size() / 5;
if(mid == 0) mid++;
for(int i = 0; i < mid; i++) {
last = Query(v[i]);
}
}
vector<int> lu, lv(v.begin(), v.begin() + mid), ru, rv(v.begin() + mid, v.end());
for(int i = 0; i < u.size(); i++) {
if(lu.size() == lv.size()) {
ru.emplace_back(u[i]);
} else if(ru.size() == rv.size()) {
lu.emplace_back(u[i]);
} else {
int rep = Query(u[i]);
if(rep == last) {
lu.emplace_back(u[i]);
} else {
ru.emplace_back(u[i]);
}
last = rep;
}
}
solve(lu, lv, 1);
solve(ru, rv, 0);
}
void split(vector<int> v) {
random_shuffle(v.begin(), v.end(), RNG());
vector<int> l, r;
int last = -1;
for(int i = 0; i < v.size(); i++) {
if(r.size() == v.size() / 2) {
l.emplace_back(v[i]);
continue;
}
int rep = Query(v[i]);
if(rep == last) {
l.emplace_back(v[i]);
} else {
r.emplace_back(v[i]);
} last = rep;
}
solve(l, r, 1);
}
void Solve(int N) {
vector<int> v(2 * N);
iota(v.begin(), v.end(), 1);
split(v);
}
Compilation message (stderr)
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:26:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(mid == u.size()) mid--;
~~~~^~~~~~~~~~~
minerals.cpp:27:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = mid; i < v.size(); i++) {
~~^~~~~~~~~~
minerals.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < u.size(); i++) {
~~^~~~~~~~~~
minerals.cpp: In function 'void split(std::vector<int>)':
minerals.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:46:4: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(rep == last) {
^~
# | 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... |