#include <bits/stdc++.h>
#define f first
#define s second
#define ent '\n'
typedef long long ll;
using namespace std;
struct asd{
int a, b, w, ca, cb;
};
vector<int> ask(int i);
const string out[2]={"NO\n","YES\n"};
const ll dx[]={0,1,0,-1,-1,1,1,-1};
const ll dy[]={1,0,-1,0,-1,1,-1,1};
const int mod=998244353;
const int md=1e9+7;
const int mx=2e5+12;
const bool T=0;
vector<int> ans[mx]
int ma;
vector<int> Ask(int i){
if(ans[i].size()>0){
return ans[i];
}
ans[i]=ask(i);
return ans[i];
}
int find(int l,int r,int x,int left,int right){
if(!x || l>r)return -1;
int mid=l+r>>1, cnt=0;
for(int i=mid;i<=r;i++){
auto a=ask(i);
if(a[0]+a[1]<ma){
if(a[0]+a[1]==0){
return i;
}
cnt++;
}
else{
int t=rand()%2;
if(t){
int val=find(i+1, r, a[1] - right, a[0], right);
if(val!=-1){
return val;
}
return find(l, mid-1, a[0] - left - cnt, left, a[1] + cnt);
}
int val=find(l, mid-1, a[0] - left - cnt, left, a[1] + cnt);
if(val!=-1){
return val;
}
return find(i+1, r, a[1] - right, a[0], right);
}
}
return find(l, mid-1, x-cnt, left, right - cnt);
}
int find_best(int n){
srand(time(0));
int pos=0, c=0;
for(int i=0;i<478;i++){
auto a=Ask(i);
if(a[0]+a[1]==0){
return i;
}
if(a[0]+a[1]>ma){
ma=a[0]+a[1];
}
}
for(int i=0;i<478;i++){
auto a=Ask(i);
if(a[0]+a[1]!=ma){
c++;
}
}
return find(478, n-1, ma - c, c, 0);
}
Compilation message
prize.cpp:23:1: error: expected initializer before 'int'
23 | int ma;
| ^~~
prize.cpp: In function 'std::vector<int> Ask(int)':
prize.cpp:26:8: error: 'ans' was not declared in this scope; did you mean 'abs'?
26 | if(ans[i].size()>0){
| ^~~
| abs
prize.cpp:29:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
29 | ans[i]=ask(i);
| ^~~
| abs
prize.cpp: In function 'int find(int, int, int, int, int)':
prize.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int mid=l+r>>1, cnt=0;
| ~^~
prize.cpp:38:22: error: 'ma' was not declared in this scope; did you mean 'a'?
38 | if(a[0]+a[1]<ma){
| ^~
| a
prize.cpp: In function 'int find_best(int)':
prize.cpp:71:22: error: 'ma' was not declared in this scope; did you mean 'a'?
71 | if(a[0]+a[1]>ma){
| ^~
| a
prize.cpp:77:23: error: 'ma' was not declared in this scope; did you mean 'a'?
77 | if(a[0]+a[1]!=ma){
| ^~
| a
prize.cpp:81:27: error: 'ma' was not declared in this scope; did you mean 'mx'?
81 | return find(478, n-1, ma - c, c, 0);
| ^~
| mx
prize.cpp:65:9: warning: unused variable 'pos' [-Wunused-variable]
65 | int pos=0, c=0;
| ^~~