#ifndef GRADER
#include "prize.h"
#endif
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
int find_best(int n) {
map<int,vi> qs;
map<int,set<int>> ma;
set<pi> intervals = {{0,n-1}};
auto removeivs = [&](int l, int r) {
intervals.erase(intervals.lower_bound(pi{l,-oo}), intervals.upper_bound(pi{r,-oo}));
};
while(!intervals.empty()) {
auto iv = *intervals.begin();
intervals.erase(intervals.begin());
int mid = (iv.first+iv.second+1)/2;
auto v = qs[mid] = ask(mid);
int type = v[0]+v[1];
if(type==0) return mid;
auto [it,good] = ma[type].insert(mid);
if(iv.first<=mid-1) intervals.insert(pi{iv.first,mid-1});
if(mid+1<=iv.second) intervals.insert(pi{mid+1,iv.second});
if(it==ma[type].begin() ) {
if(v[0]==0) removeivs(0,mid);
} else {
auto vv = qs[*prev(it)];
if(vv[0]==v[0]) removeivs(*prev(it),mid);
}
if(next(it)==ma[type].end()) {
if(v[1]==0) removeivs(mid,n);
} else {
auto vv = qs[*(++it)];
if(vv[1]==v[1]) removeivs(mid,*it);
}
}
return -1;
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:31:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | auto [it,good] = ma[type].insert(mid);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
284 KB |
Output is correct |
4 |
Correct |
1 ms |
280 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
280 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
264 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
268 KB |
Output is correct |
10 |
Correct |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
12 |
Correct |
2 ms |
288 KB |
Output is correct |
13 |
Correct |
6 ms |
264 KB |
Output is correct |
14 |
Correct |
3 ms |
200 KB |
Output is correct |
15 |
Correct |
8 ms |
264 KB |
Output is correct |
16 |
Correct |
56 ms |
756 KB |
Output is correct |
17 |
Correct |
1 ms |
200 KB |
Output is correct |
18 |
Correct |
58 ms |
936 KB |
Output is correct |
19 |
Correct |
1 ms |
200 KB |
Output is correct |
20 |
Correct |
9 ms |
444 KB |
Output is correct |
21 |
Correct |
22 ms |
452 KB |
Output is correct |
22 |
Correct |
6 ms |
324 KB |
Output is correct |
23 |
Correct |
2 ms |
280 KB |
Output is correct |
24 |
Correct |
2 ms |
284 KB |
Output is correct |
25 |
Correct |
18 ms |
604 KB |
Output is correct |
26 |
Correct |
28 ms |
620 KB |
Output is correct |
27 |
Correct |
1 ms |
288 KB |
Output is correct |
28 |
Correct |
34 ms |
884 KB |
Output is correct |
29 |
Correct |
38 ms |
752 KB |
Output is correct |
30 |
Correct |
54 ms |
924 KB |
Output is correct |
31 |
Correct |
1 ms |
272 KB |
Output is correct |
32 |
Correct |
5 ms |
308 KB |
Output is correct |
33 |
Correct |
1 ms |
200 KB |
Output is correct |
34 |
Correct |
16 ms |
404 KB |
Output is correct |
35 |
Correct |
3 ms |
256 KB |
Output is correct |
36 |
Correct |
13 ms |
420 KB |
Output is correct |
37 |
Correct |
2 ms |
276 KB |
Output is correct |
38 |
Correct |
1 ms |
268 KB |
Output is correct |
39 |
Correct |
28 ms |
504 KB |
Output is correct |
40 |
Correct |
40 ms |
832 KB |
Output is correct |
41 |
Correct |
18 ms |
712 KB |
Output is correct |
42 |
Correct |
31 ms |
648 KB |
Output is correct |
43 |
Correct |
25 ms |
520 KB |
Output is correct |
44 |
Correct |
19 ms |
448 KB |
Output is correct |
45 |
Correct |
17 ms |
392 KB |
Output is correct |
46 |
Correct |
1 ms |
328 KB |
Output is correct |
47 |
Correct |
17 ms |
512 KB |
Output is correct |
48 |
Correct |
42 ms |
704 KB |
Output is correct |
49 |
Correct |
3 ms |
324 KB |
Output is correct |
50 |
Correct |
53 ms |
944 KB |
Output is correct |
51 |
Correct |
23 ms |
528 KB |
Output is correct |
52 |
Correct |
1 ms |
276 KB |
Output is correct |
53 |
Correct |
2 ms |
272 KB |
Output is correct |
54 |
Correct |
21 ms |
556 KB |
Output is correct |
55 |
Correct |
1 ms |
200 KB |
Output is correct |
56 |
Correct |
52 ms |
992 KB |
Output is correct |
57 |
Correct |
24 ms |
780 KB |
Output is correct |
58 |
Correct |
41 ms |
748 KB |
Output is correct |
59 |
Correct |
29 ms |
636 KB |
Output is correct |
60 |
Correct |
25 ms |
524 KB |
Output is correct |
61 |
Correct |
3 ms |
284 KB |
Output is correct |
62 |
Correct |
1 ms |
284 KB |
Output is correct |
63 |
Correct |
2 ms |
280 KB |
Output is correct |
64 |
Correct |
1 ms |
272 KB |
Output is correct |
65 |
Correct |
2 ms |
320 KB |
Output is correct |
66 |
Correct |
1 ms |
284 KB |
Output is correct |
67 |
Correct |
1 ms |
200 KB |
Output is correct |
68 |
Correct |
1 ms |
200 KB |
Output is correct |
69 |
Correct |
2 ms |
200 KB |
Output is correct |
70 |
Correct |
1 ms |
292 KB |
Output is correct |
71 |
Correct |
42 ms |
964 KB |
Output is correct |
72 |
Correct |
8 ms |
292 KB |
Output is correct |
73 |
Correct |
48 ms |
944 KB |
Output is correct |
74 |
Correct |
57 ms |
880 KB |
Output is correct |
75 |
Correct |
1 ms |
200 KB |
Output is correct |
76 |
Correct |
52 ms |
876 KB |
Output is correct |
77 |
Correct |
49 ms |
900 KB |
Output is correct |
78 |
Correct |
6 ms |
328 KB |
Output is correct |
79 |
Correct |
31 ms |
592 KB |
Output is correct |
80 |
Correct |
54 ms |
968 KB |
Output is correct |
81 |
Correct |
61 ms |
996 KB |
Output is correct |
82 |
Correct |
46 ms |
908 KB |
Output is correct |
83 |
Correct |
2 ms |
256 KB |
Output is correct |
84 |
Correct |
39 ms |
928 KB |
Output is correct |
85 |
Correct |
49 ms |
904 KB |
Output is correct |
86 |
Correct |
6 ms |
328 KB |
Output is correct |
87 |
Correct |
3 ms |
200 KB |
Output is correct |
88 |
Correct |
8 ms |
332 KB |
Output is correct |
89 |
Correct |
6 ms |
328 KB |
Output is correct |
90 |
Correct |
2 ms |
200 KB |
Output is correct |
91 |
Correct |
4 ms |
328 KB |
Output is correct |
92 |
Correct |
1 ms |
200 KB |
Output is correct |
93 |
Correct |
3 ms |
328 KB |
Output is correct |
94 |
Correct |
4 ms |
328 KB |
Output is correct |
95 |
Correct |
4 ms |
316 KB |
Output is correct |
96 |
Correct |
6 ms |
312 KB |
Output is correct |
97 |
Correct |
1 ms |
200 KB |
Output is correct |