#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn=2e5+5;
int n,l[mxn],r[mxn],color[mxn],tree[mxn],p[mxn];
void update(int idx,int val){
while(idx<=n){
tree[idx]+=val;
idx+=(idx&(-idx));
}
}
int query(int l,int r){
if(l!=1){
return query(1,r)-query(1,l-1);
}
int idx=r;
int ans=0;
while(idx>0){
ans+=tree[idx];
idx-=(idx&(-idx));
}
return ans;
}
pii fnd(int idx){
if(l[idx]!=-1){
return {l[idx],r[idx]};
}
vector<int>res=ask(idx);
l[idx]=res[0];
r[idx]=res[1];
return {res[0],res[1]};
}
pii funk(int idx){
int l=idx,r=idx;
while(p[l]==1) l--;
while(p[r]==1) r++;
return {l,r};
}
int find_best(int N) {
n=N;
memset(l,-1,sizeof(l));
memset(r,-1,sizeof(r));
int qq=500;
int mx=0;
while(qq--){
int idx=rng()%n;
if(l[idx]!=-1){
qq++;
continue;
}
vector<int> res = ask(idx);
l[idx]=res[0];
r[idx]=res[1];
if(l[idx]+r[idx]==0) return idx;
mx=max(mx,l[idx]+r[idx]);
}
for()
int qw=10;
int cnt=mx;
while(cnt>0&&qw--){
int l=1,r=n;
while(l<=r){
int m=(l+r)/2;
pii ppp=funk(m);
int a=ppp.F,b=ppp.S;
if(a<l&&b>r) break;
if(a>=l&&b<=r){
if(abs(a-m)<abs(b-m)){
m=a;
}
else{
m=b;
}
}
else if(a>=l){
m=a;
}
else{
m=b;
}
if(fnd(m).F+fnd(m).S<mx){
cnt--;
update(m+1,1);
if(fnd(m).F+fnd(m).S==0) return m;
p[m]=1;
break;
}
if(fnd(m).F-query(1,m+1)>0){
r=m-1;
}
else{
l=m+1;
}
}
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:69:6: error: expected primary-expression before ')' token
69 | for()
| ^
prize.cpp:72:2: error: expected primary-expression before 'while'
72 | while(cnt>0&&qw--){
| ^~~~~
prize.cpp:71:13: error: expected ')' before 'while'
71 | int cnt=mx;
| ^
| )
72 | while(cnt>0&&qw--){
| ~~~~~
prize.cpp:69:5: note: to match this '('
69 | for()
| ^
prize.cpp:72:15: error: 'qw' was not declared in this scope; did you mean 'qq'?
72 | while(cnt>0&&qw--){
| ^~
| qq
prize.cpp:108:1: warning: control reaches end of non-void function [-Wreturn-type]
108 | }
| ^