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<vector>
#include<set>
#include<random>
#include<algorithm>
#include<iostream>
using namespace std;
int n, s;
random_device rd;
mt19937 g(rd());
const int maxn = 45002;
int mxn = 45000;
int dp0[maxn+1] ,nxt0[maxn+1];
int cut[2*maxn];
double phi = 0.61803398874989484820458683436564;
void solve(vector<int>& in, int s, int e, vector<int>& rest, int f1) {//f1 - is_in?
if (in.size() == 1) { Answer(in[0], rest[0]); return; }
vector<int> in1, in2;
int sz1 = (double)in.size() * phi;
if (in.size() <= mxn) sz1 = in.size() - nxt0[in.size()];
int sz = 0;
vector<int> rest1, rest2;
int m = s + sz1 - 1;
for (int i = 0; i < sz1; i++) in1.push_back(in[i]);
for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
for (int i : in2) sz = Query(i);
for (int j : rest) {
if (cut[j] <= m) { rest1.push_back(j); continue; }
if (rest1.size() == sz1) { rest2.push_back(j); continue; }
if (rest2.size() == rest.size() - sz1) { rest1.push_back(j); continue; }
int u = Query(j);
if (u == sz) {
if (f1) rest1.push_back(j);
else rest2.push_back(j);
}
else {
sz = u;
if (f1) rest2.push_back(j);
else rest1.push_back(j);
}
}
solve(in1, s, m, rest1, f1);
solve(in2, m + 1, e, rest2, 1-f1);
}
void Solve(int N) {
dp0[1] = 0;
for (int i = 2; i <= maxn; i++) {
int l = 1, r = i / 2, m;
while (r > l) {
m = (l + r) / 2;
int vm = dp0[m] + dp0[i - m] + m + i;
int vm1 = dp0[m+1] + dp0[i - m - 1] + m + 1 + i;
if (vm > vm1) l = m + 1;
else r = m;
}
dp0[i] = dp0[l] + dp0[i - l] + l + i;
nxt0[i] = l;
}
//for (int i = 2; i < 1000; i++) cout << i << ' ' << dp0[i] << ' ' << nxt0[i] << endl;
//for (int u = 38000; u <= 45000; u += 1000) cout << u << ' ' << 2 * u + dp0[u] << endl;
n = N; s = n << 1;
int sz = 0;
vector<int> in, rest;
vector<int> vec(s);
for (int i = 0; i < s; i++)vec[i] = i + 1;
shuffle(vec.begin(), vec.end(), g);
for (int i : vec) {
if (in.size() < n) {
int u = Query(i);
if (u > sz) {
sz = u;
in.push_back(i);
}
else {
rest.push_back(i);
cut[i] = in.size();
}
}
else {
rest.push_back(i);
cut[i] = in.size();
}
}
solve(in, 0, n-1, rest, 1);
}//45000?
Compilation message (stderr)
minerals.cpp: In function 'void solve(std::vector<int>&, int, int, std::vector<int>&, int)':
minerals.cpp:22:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if (in.size() <= mxn) sz1 = in.size() - nxt0[in.size()];
| ~~~~~~~~~~^~~~~~
minerals.cpp:28:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = sz1; i < in.size(); i++) in2.push_back(in[i]);
| ~~^~~~~~~~~~~
minerals.cpp:33:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
33 | if (rest1.size() == sz1) { rest2.push_back(j); continue; }
| ~~~~~~~~~~~~~^~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:75:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
75 | if (in.size() < n) {
| ~~~~~~~~~~^~~
# | 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... |