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 "prize.h"
#include <bits/stdc++.h>
typedef long long ll;
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
using namespace std;
int find_best(int n) {
int mn = 0;
FOR(i, min(530, n)){
auto res = ask(i);
mn = max(mn, res[0] + res[1]);
}
vector<int> pos;
vector<vector<int>> val(n);
int l = 0, r = 1;
FOR(i, mn){
while(r < n - 1){
auto ret = ask(r);
if(ret[0] + ret[1] != mn) break;
if(ret[0] > i) break;
r += (r - l);
if(r >= n){
r = n - 1;
break;
}
}
while(l < r){
int mid = (l + r) / 2;
vector<int> ret;
if(val[mid].size()) ret = val[mid];
else ret = val[mid] = ask(mid);
if(ret[0] + ret[1] == 0) return mid;
if(ret[0] + ret[1] != mn) r = mid;
else if(ret[0] > i) r = mid - 1;
else l = mid + 1;
}
pos.push_back(r);
if(r != n - 1) {l++; r += 2;}
}
for (auto i : pos) {
vector<int> ret;
if(val[i].size()) ret = val[i];
else ret = val[i] = ask(i);
if(ret[0] + ret[1] == 0) return i;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |