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 <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
vector <int> L, R;
void discover(int mid) {
if (L[mid] == -1) {
vector <int> resp = ask(mid);
L[mid] = resp[0];
R[mid] = resp[1];
}
}
map <int, int> mp[N_MAX + 2];
int solve(int l, int r) {
int mid = (l + r) / 2;
discover(mid);
int cntLess = L[mid] + R[mid];
if (cntLess == 0) {
return mid;
}
mp[cntLess][mid] = L[mid];
auto it = mp[cntLess].find(mid);
if (l < mid && (it == mp[cntLess].begin() || L[mid] - prev(it)->second > 0)) {
int sl = solve(l, mid - 1);
if (sl != -1) {
return sl;
}
}
if (mid < r && (it == mp[cntLess].end() || next(it)->second - L[mid] > 0)) {
int sr = solve(mid + 1, r);
if (sr != -1) {
return sr;
}
}
return -1;
}
int find_best(int N) {
L = vector <int> (N, -1);
R = vector <int> (N, -1);
return solve(0, N - 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |