#include "prize.h"
#include <bits/stdc++.h>
#define ll int
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e9;
const ll mod=1e9+7;
const ll N=2e5+7;
const ld eps=1e-9;
vll x;
set<ll> g;
ll cnt[N];
int find_best(int n) {
ll i;
if(n<=5000){
for(i=0;i<n;i++){
x=ask(i);
if(x[0]+x[1]==0)return i;
}
}
ll mx=0;
ll c=0;
for(i=0;i<500;i++){
x=ask(i);
cnt[i]=x[0]+x[1];
if(cnt[i]==0)return i;
chmax(mx,cnt[i]);
}
ll y=0;
for(i=0;i<500;i++)c+=(cnt[i]<mx ? 1 : 0);
ll L=500;
ll lst[n+5];
for(i=0;i<mx;i++){
ll l=L,r=n;
while(l+1<r){
ll m=(l+r)/2;
if(cnt[m]==0){
x=ask(m);
lst[m]=x[0];
cnt[m]=x[0]+x[1];
if(cnt[m]==0)return m;
}
if(cnt[m]<mx){
g.ins(m);
r=m;
continue;
}
if(lst[m]<=c){
l=m;
}else{
r=m;
}
}
if(cnt[l]==0){
x=ask(l);
cnt[l]=x[0]+x[1];
if(cnt[l]==0)return l;
if(cnt[l]<mx)g.ins(l);
}
if(r<n && cnt[r]==0){
x=ask(r);
cnt[r]=x[0]+x[1];
if(cnt[r]==0)return r;
if(cnt[r]<mx)g.ins(r);
}
L=*g.lb(L)+1;
c++;
while(g.sz && *g.rbegin()>=L){
g.erase(--g.end());
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |