#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 B=600;
const int MX=2e5+10;
int N,X=0;
unordered_map<int,int>mn,mx;
vi L(MX,-1), R(MX,-1);
vi query(int i){
if(L[i]==-1){
vi vec=ask(i);
L[i]=vec[0]; R[i]=vec[1];
if(L[i]+R[i]==X){
if(!mn.count(L[i])) mn[L[i]]=i, mx[L[i]]=i;
if(ckmin(mn[L[i]],i)){
int j=i+1;
while(j<N && L[j]==-1){
L[j]=L[i], R[j]=R[i];
j++;
}
}
if(ckmax(mx[L[i]],i)){
int j=i-1;
while(j>=0 && L[j]==-1){
L[j]=L[i], R[j]=R[i];
j--;
}
}
}
}
return vi{L[i],R[i]};
}
int find_best(int N) {
::N=N;
int 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;
}
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:112:1: warning: control reaches end of non-void function [-Wreturn-type]
112 | }
| ^
prize.cpp:85:12: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
85 | int m=(l+r)/2;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1876 KB |
Output is correct |
2 |
Correct |
7 ms |
1744 KB |
Output is correct |
3 |
Correct |
11 ms |
1920 KB |
Output is correct |
4 |
Correct |
5 ms |
1872 KB |
Output is correct |
5 |
Correct |
7 ms |
1872 KB |
Output is correct |
6 |
Correct |
1 ms |
1860 KB |
Output is correct |
7 |
Correct |
10 ms |
1872 KB |
Output is correct |
8 |
Correct |
9 ms |
1872 KB |
Output is correct |
9 |
Correct |
5 ms |
1872 KB |
Output is correct |
10 |
Correct |
6 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1872 KB |
Output is correct |
2 |
Correct |
4 ms |
1888 KB |
Output is correct |
3 |
Correct |
9 ms |
1872 KB |
Output is correct |
4 |
Correct |
9 ms |
1876 KB |
Output is correct |
5 |
Correct |
9 ms |
1872 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
6 ms |
1872 KB |
Output is correct |
8 |
Correct |
4 ms |
1876 KB |
Output is correct |
9 |
Correct |
9 ms |
1876 KB |
Output is correct |
10 |
Correct |
7 ms |
1872 KB |
Output is correct |
11 |
Correct |
7 ms |
1848 KB |
Output is correct |
12 |
Correct |
6 ms |
1744 KB |
Output is correct |
13 |
Correct |
12 ms |
1872 KB |
Output is correct |
14 |
Correct |
7 ms |
1876 KB |
Output is correct |
15 |
Correct |
17 ms |
1876 KB |
Output is correct |
16 |
Partially correct |
35 ms |
1904 KB |
Partially correct - number of queries: 5359 |
17 |
Correct |
7 ms |
1860 KB |
Output is correct |
18 |
Partially correct |
46 ms |
1892 KB |
Partially correct - number of queries: 6199 |
19 |
Correct |
20 ms |
1880 KB |
Output is correct |
20 |
Correct |
25 ms |
1872 KB |
Output is correct |
21 |
Correct |
24 ms |
1884 KB |
Output is correct |
22 |
Correct |
10 ms |
1876 KB |
Output is correct |
23 |
Correct |
6 ms |
1872 KB |
Output is correct |
24 |
Correct |
5 ms |
1872 KB |
Output is correct |
25 |
Correct |
31 ms |
1896 KB |
Output is correct |
26 |
Correct |
23 ms |
1868 KB |
Output is correct |
27 |
Correct |
9 ms |
1872 KB |
Output is correct |
28 |
Partially correct |
44 ms |
1996 KB |
Partially correct - number of queries: 5558 |
29 |
Correct |
32 ms |
1880 KB |
Output is correct |
30 |
Partially correct |
76 ms |
1900 KB |
Partially correct - number of queries: 6174 |
31 |
Correct |
5 ms |
1876 KB |
Output is correct |
32 |
Correct |
8 ms |
1872 KB |
Output is correct |
33 |
Correct |
1 ms |
1872 KB |
Output is correct |
34 |
Correct |
21 ms |
1872 KB |
Output is correct |
35 |
Correct |
8 ms |
1872 KB |
Output is correct |
36 |
Correct |
20 ms |
1872 KB |
Output is correct |
37 |
Correct |
11 ms |
1872 KB |
Output is correct |
38 |
Correct |
7 ms |
1744 KB |
Output is correct |
39 |
Correct |
33 ms |
1880 KB |
Output is correct |
40 |
Partially correct |
56 ms |
1876 KB |
Partially correct - number of queries: 5407 |
41 |
Correct |
26 ms |
1872 KB |
Output is correct |
42 |
Correct |
29 ms |
2008 KB |
Output is correct |
43 |
Correct |
35 ms |
1896 KB |
Output is correct |
44 |
Correct |
45 ms |
1872 KB |
Output is correct |
45 |
Correct |
11 ms |
1900 KB |
Output is correct |
46 |
Correct |
3 ms |
2000 KB |
Output is correct |
47 |
Correct |
25 ms |
2012 KB |
Output is correct |
48 |
Correct |
22 ms |
1904 KB |
Output is correct |
49 |
Correct |
7 ms |
1880 KB |
Output is correct |
50 |
Partially correct |
48 ms |
1872 KB |
Partially correct - number of queries: 6186 |
51 |
Correct |
21 ms |
1884 KB |
Output is correct |
52 |
Correct |
7 ms |
1872 KB |
Output is correct |
53 |
Correct |
10 ms |
1872 KB |
Output is correct |
54 |
Correct |
30 ms |
1872 KB |
Output is correct |
55 |
Correct |
6 ms |
1744 KB |
Output is correct |
56 |
Partially correct |
57 ms |
1900 KB |
Partially correct - number of queries: 6215 |
57 |
Correct |
41 ms |
1896 KB |
Output is correct |
58 |
Correct |
46 ms |
1872 KB |
Output is correct |
59 |
Correct |
35 ms |
2024 KB |
Output is correct |
60 |
Correct |
29 ms |
1996 KB |
Output is correct |
61 |
Correct |
7 ms |
1872 KB |
Output is correct |
62 |
Correct |
6 ms |
1872 KB |
Output is correct |
63 |
Correct |
5 ms |
1872 KB |
Output is correct |
64 |
Correct |
8 ms |
1876 KB |
Output is correct |
65 |
Correct |
5 ms |
1872 KB |
Output is correct |
66 |
Correct |
11 ms |
1860 KB |
Output is correct |
67 |
Correct |
7 ms |
1872 KB |
Output is correct |
68 |
Correct |
5 ms |
1876 KB |
Output is correct |
69 |
Correct |
11 ms |
1872 KB |
Output is correct |
70 |
Correct |
4 ms |
1872 KB |
Output is correct |
71 |
Partially correct |
65 ms |
1876 KB |
Partially correct - number of queries: 6962 |
72 |
Correct |
11 ms |
1884 KB |
Output is correct |
73 |
Partially correct |
58 ms |
1880 KB |
Partially correct - number of queries: 6810 |
74 |
Partially correct |
69 ms |
1896 KB |
Partially correct - number of queries: 6884 |
75 |
Correct |
8 ms |
1872 KB |
Output is correct |
76 |
Partially correct |
51 ms |
1900 KB |
Partially correct - number of queries: 6031 |
77 |
Partially correct |
44 ms |
1880 KB |
Partially correct - number of queries: 6944 |
78 |
Correct |
15 ms |
1872 KB |
Output is correct |
79 |
Correct |
17 ms |
1896 KB |
Output is correct |
80 |
Partially correct |
57 ms |
1884 KB |
Partially correct - number of queries: 6991 |
81 |
Partially correct |
66 ms |
1904 KB |
Partially correct - number of queries: 6971 |
82 |
Partially correct |
30 ms |
1896 KB |
Partially correct - number of queries: 6881 |
83 |
Correct |
9 ms |
1872 KB |
Output is correct |
84 |
Partially correct |
57 ms |
1872 KB |
Partially correct - number of queries: 5770 |
85 |
Partially correct |
51 ms |
1992 KB |
Partially correct - number of queries: 6848 |
86 |
Correct |
5 ms |
1872 KB |
Output is correct |
87 |
Correct |
6 ms |
1872 KB |
Output is correct |
88 |
Correct |
12 ms |
1872 KB |
Output is correct |
89 |
Correct |
8 ms |
1884 KB |
Output is correct |
90 |
Correct |
10 ms |
1872 KB |
Output is correct |
91 |
Correct |
6 ms |
1880 KB |
Output is correct |
92 |
Correct |
7 ms |
1872 KB |
Output is correct |
93 |
Correct |
8 ms |
1872 KB |
Output is correct |
94 |
Correct |
12 ms |
1920 KB |
Output is correct |
95 |
Correct |
11 ms |
1872 KB |
Output is correct |
96 |
Correct |
8 ms |
1872 KB |
Output is correct |
97 |
Correct |
8 ms |
1872 KB |
Output is correct |