#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
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 |
1 |
Correct |
4 ms |
1884 KB |
Output is correct |
2 |
Correct |
4 ms |
1876 KB |
Output is correct |
3 |
Correct |
3 ms |
1872 KB |
Output is correct |
4 |
Correct |
3 ms |
1880 KB |
Output is correct |
5 |
Correct |
5 ms |
1872 KB |
Output is correct |
6 |
Correct |
1 ms |
1880 KB |
Output is correct |
7 |
Correct |
5 ms |
1872 KB |
Output is correct |
8 |
Correct |
5 ms |
1872 KB |
Output is correct |
9 |
Correct |
4 ms |
1880 KB |
Output is correct |
10 |
Correct |
4 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1872 KB |
Output is correct |
2 |
Correct |
6 ms |
1872 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
10 ms |
1744 KB |
Output is correct |
5 |
Correct |
7 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
8 ms |
1856 KB |
Output is correct |
8 |
Correct |
8 ms |
1744 KB |
Output is correct |
9 |
Correct |
3 ms |
1872 KB |
Output is correct |
10 |
Correct |
6 ms |
1872 KB |
Output is correct |
11 |
Correct |
12 ms |
1872 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
10 ms |
1872 KB |
Output is correct |
14 |
Correct |
9 ms |
1872 KB |
Output is correct |
15 |
Correct |
24 ms |
1872 KB |
Output is correct |
16 |
Partially correct |
67 ms |
1876 KB |
Partially correct - number of queries: 7218 |
17 |
Correct |
3 ms |
1880 KB |
Output is correct |
18 |
Partially correct |
89 ms |
1872 KB |
Partially correct - number of queries: 8374 |
19 |
Correct |
4 ms |
1872 KB |
Output is correct |
20 |
Correct |
13 ms |
1872 KB |
Output is correct |
21 |
Correct |
42 ms |
1872 KB |
Output is correct |
22 |
Correct |
10 ms |
1872 KB |
Output is correct |
23 |
Correct |
5 ms |
1872 KB |
Output is correct |
24 |
Correct |
8 ms |
1872 KB |
Output is correct |
25 |
Correct |
22 ms |
1860 KB |
Output is correct |
26 |
Correct |
49 ms |
1876 KB |
Output is correct |
27 |
Correct |
9 ms |
1872 KB |
Output is correct |
28 |
Partially correct |
90 ms |
1872 KB |
Partially correct - number of queries: 7902 |
29 |
Partially correct |
68 ms |
1876 KB |
Partially correct - number of queries: 6143 |
30 |
Partially correct |
62 ms |
1860 KB |
Partially correct - number of queries: 8307 |
31 |
Correct |
5 ms |
1872 KB |
Output is correct |
32 |
Correct |
11 ms |
1880 KB |
Output is correct |
33 |
Correct |
1 ms |
1872 KB |
Output is correct |
34 |
Correct |
24 ms |
1880 KB |
Output is correct |
35 |
Correct |
6 ms |
1744 KB |
Output is correct |
36 |
Correct |
25 ms |
1872 KB |
Output is correct |
37 |
Correct |
9 ms |
1876 KB |
Output is correct |
38 |
Correct |
6 ms |
1744 KB |
Output is correct |
39 |
Correct |
37 ms |
1872 KB |
Output is correct |
40 |
Partially correct |
47 ms |
1872 KB |
Partially correct - number of queries: 7177 |
41 |
Partially correct |
43 ms |
1860 KB |
Partially correct - number of queries: 5238 |
42 |
Partially correct |
33 ms |
1744 KB |
Partially correct - number of queries: 5238 |
43 |
Correct |
44 ms |
1872 KB |
Output is correct |
44 |
Correct |
34 ms |
1860 KB |
Output is correct |
45 |
Correct |
32 ms |
1872 KB |
Output is correct |
46 |
Correct |
5 ms |
1880 KB |
Output is correct |
47 |
Correct |
43 ms |
1860 KB |
Output is correct |
48 |
Partially correct |
62 ms |
1872 KB |
Partially correct - number of queries: 6334 |
49 |
Correct |
10 ms |
1872 KB |
Output is correct |
50 |
Partially correct |
85 ms |
1872 KB |
Partially correct - number of queries: 8370 |
51 |
Correct |
39 ms |
1872 KB |
Output is correct |
52 |
Correct |
6 ms |
1860 KB |
Output is correct |
53 |
Correct |
6 ms |
1876 KB |
Output is correct |
54 |
Correct |
37 ms |
1852 KB |
Output is correct |
55 |
Correct |
4 ms |
1872 KB |
Output is correct |
56 |
Partially correct |
57 ms |
1872 KB |
Partially correct - number of queries: 8374 |
57 |
Partially correct |
43 ms |
1864 KB |
Partially correct - number of queries: 6236 |
58 |
Partially correct |
46 ms |
1744 KB |
Partially correct - number of queries: 6320 |
59 |
Partially correct |
59 ms |
1876 KB |
Partially correct - number of queries: 5235 |
60 |
Correct |
20 ms |
1872 KB |
Output is correct |
61 |
Correct |
7 ms |
1872 KB |
Output is correct |
62 |
Correct |
4 ms |
1872 KB |
Output is correct |
63 |
Correct |
5 ms |
1744 KB |
Output is correct |
64 |
Correct |
7 ms |
1872 KB |
Output is correct |
65 |
Correct |
5 ms |
1876 KB |
Output is correct |
66 |
Correct |
8 ms |
1872 KB |
Output is correct |
67 |
Correct |
3 ms |
1876 KB |
Output is correct |
68 |
Correct |
4 ms |
1872 KB |
Output is correct |
69 |
Correct |
9 ms |
1868 KB |
Output is correct |
70 |
Correct |
5 ms |
1872 KB |
Output is correct |
71 |
Partially correct |
64 ms |
1872 KB |
Partially correct - number of queries: 8270 |
72 |
Correct |
12 ms |
1872 KB |
Output is correct |
73 |
Partially correct |
66 ms |
1872 KB |
Partially correct - number of queries: 8159 |
74 |
Partially correct |
80 ms |
1872 KB |
Partially correct - number of queries: 8219 |
75 |
Correct |
6 ms |
1872 KB |
Output is correct |
76 |
Partially correct |
67 ms |
1876 KB |
Partially correct - number of queries: 7113 |
77 |
Partially correct |
42 ms |
1872 KB |
Partially correct - number of queries: 7051 |
78 |
Correct |
8 ms |
1872 KB |
Output is correct |
79 |
Correct |
30 ms |
1876 KB |
Output is correct |
80 |
Partially correct |
77 ms |
1872 KB |
Partially correct - number of queries: 8409 |
81 |
Partially correct |
66 ms |
1872 KB |
Partially correct - number of queries: 8420 |
82 |
Partially correct |
68 ms |
1872 KB |
Partially correct - number of queries: 8353 |
83 |
Correct |
4 ms |
1872 KB |
Output is correct |
84 |
Partially correct |
53 ms |
1876 KB |
Partially correct - number of queries: 6970 |
85 |
Partially correct |
76 ms |
1880 KB |
Partially correct - number of queries: 8433 |
86 |
Correct |
5 ms |
1872 KB |
Output is correct |
87 |
Correct |
6 ms |
1872 KB |
Output is correct |
88 |
Correct |
5 ms |
1872 KB |
Output is correct |
89 |
Correct |
6 ms |
1872 KB |
Output is correct |
90 |
Correct |
5 ms |
1872 KB |
Output is correct |
91 |
Correct |
6 ms |
1872 KB |
Output is correct |
92 |
Correct |
6 ms |
1872 KB |
Output is correct |
93 |
Correct |
7 ms |
1880 KB |
Output is correct |
94 |
Correct |
10 ms |
1872 KB |
Output is correct |
95 |
Correct |
8 ms |
1872 KB |
Output is correct |
96 |
Correct |
8 ms |
1872 KB |
Output is correct |
97 |
Correct |
5 ms |
1880 KB |
Output is correct |