//#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int ans = -1,c = 0;
const int MAX = 2e5 + 1;
vector<int> v[MAX];
void as(int i){
if(v[i].size() != 0) return;
v[i] = ask(i);
if(v[i][0] + v[i][1] == 0)
ans = i;
}
bool is(int i){
if(v[i].size() == 0) as(i);
// cout << i << " " << v[i][0] << " " << v[i][1] << endl;
if(v[i][0] + v[i][1] == c)
return true;
return false;
}
void solve(int l,int r,int cur = 0){
// cout << l << " " << r << endl;
if(ans != -1) return;
while(!is(l) && l < r) l++;
if(ans != -1) return ;
// cout << r << endl;
while(!is(r) && l < r) r--;
// cout << r << endl;
if(ans != -1) return;
int mid = (l+r)/2;
if(l >= r || v[r][0] == v[l][0]) return;
solve(l,mid);
solve(mid+1,r);
}
int find_best(int n) {
for(int i = 0; i < min(500,n); i++){
as(i);
c = max(c,v[i][0] + v[i][1]);
}
solve(0,n-1);
return ans;
}
Compilation message
train.cpp: In function 'void as(int)':
train.cpp:12:9: error: 'ask' was not declared in this scope; did you mean 'as'?
12 | v[i] = ask(i);
| ^~~
| as