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>
using namespace std;
const int N = 200010;
#define oo 2000000000
bool asked[N];
vector<int> answer[N] , v;
vector< pair<int,int> > v2;
int mx = 0 ;
vector<int> get(int i){
if(asked[i])
return answer[i];
asked[i] = true;
answer[i] = ask(i);
if(answer[i][0] + answer[i][1] == mx) v2.push_back(make_pair(answer[i][0],i)); else v.push_back(i);
return answer[i];
}
int solve(int s,int e){
int res = e;
vector<int> v1 = get(s);
while(e >= s){
int mid = (s + e) / 2;
vector<int> cur = get(mid);
if(cur[0] + cur[1] == mx && cur[0] == v1[0])
s = mid + 1;
else {
res = mid;
e = mid - 1;
}
}
return res;
}
int find_best(int n) {
int num = sqrt(n) - 2;
int it = 0;
if(n <= 5000){
for(int i=0;i<n;i++){
vector<int> cur = get(i);
if(cur[0]+cur[1] == 0) return i;
}
}
for(int i=0;i<n && it < 480;i+=num){
vector<int> res = get(i);
int cur = res[0] + res[1];
mx = max(mx,cur);
it++;
}
for(int i=1;i<n && it < 480;i+=num){
it++;
vector<int> res = get(i);
int cur = res[0] + res[1];
mx = max(mx,cur);
}
int low = 0;
while(true){
int high = n - 1;
vector<int> cur = get(low);
if(cur[0] + cur[1] == 0) return low;
if(cur[0] + cur[1] != mx){
low++;
continue;
}
low = solve(low,high);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |