This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef pair<ll,ll>pi;
typedef vector<pi>vpi;
#define fi first
#define se second
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const ll INF=1e18;
//-------------------------------------
const int MX=2e5+10;
vi L(MX,-1), R(MX,-1);
int cnt=0;
vi query(int i){
if(L[i]==-1){
//cnt++; if(cnt>10000) assert(0);
vi vec=ask(i);
L[i]=vec[0]; R[i]=vec[1];
}
return vi{L[i],R[i]};
}
const int B=500;
int find_best(int N) {
int X=0,idx;
FOR(i,0,min(N,B)){
vi vec=query(i);
if(vec[0]==0 && vec[1]==0) return i;
if(ckmax(X,vec[0]+vec[1])) idx=i;
//if(sq(sq(X)+1)+1>N) break;
}
int done=0;
while(idx<N){
vi tmp=query(idx);
int l=idx, r=N-1, nxt=N;
while(l<=r){
int m=(l+r)/2;
vi vec=query(m);
if(vec[0]==0 && vec[1]==0) return m;
if(vec[0]+vec[1]<X) nxt=m, r=m-1;
else{
if(vec[0]==tmp[0]) l=m+1;
else r=m-1;
}
}
while(nxt<N){
vi vec=query(nxt);
if(vec[0]==0 && vec[1]==0) return nxt;
if(vec[0]+vec[1]==X) break;
nxt++;
}
idx=nxt;
done++;
}
//assert(0);
}
/*
8
3 2 3 1 3 3 2 3
*/
/*
10
3 3 2 3 3 3 1 2 3 3
*/
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
89 | }
| ^
prize.cpp:62:12: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | int m=(l+r)/2;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |