#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> ti;
typedef vector<ll> li;
typedef vector<li> lii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define LSOne(s) ((s)&(-s))
#define all(x) (x).begin(),(x).end()
ll INF=1000000000000000010;
int inf=1e9+10;
ll M=1e9+7;
int find_best(int n) {
if(n<=5000){
REP(i,0,n){
vi a=ask(i);
if(a[0]==0&&a[1]==0)return i;
}
}
int mx=0;
REP(i,0,500){
vi a=ask(i);
mx=max(mx,a[0]+a[1]);
if(a[0]+a[1]==0)return i;
}
int pos=500;
map<int,vi> mp;
while(pos<n){
bool flag=1;
vi b;
while(pos<n&&flag){
b=ask(pos);
if(b[0]+b[1]==0)return pos;
if(b[0]+b[1]!=mx)pos++;
else flag=0;
}
int l=pos+1,r=n;
auto it=mp.lower_bound(pos+1);
while(it!=mp.end()&&it->S[1]==b[1]){
l=it->F+1;
it=mp.lower_bound(l);
}
if(it!=mp.end())r=it->F;
if(r-l>2000){
vi a=ask(l+1000);
mp[l+1000]=a;
if(a[1]==b[1])l=l+1001;
else r=l+1000;
}
while(l!=r){
int m=(l+r)/2;
vi a;
if(mp[m].empty()){
a=ask(m);
mp[m]=a;
}
else a=mp[m];
if(a[0]+a[1]==0)return m;
if(b[1]==a[1])l=m+1;
else r=m;
}
pos=l+1;
}
return n-1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |