#include "prize.h"
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define maxn 200005
ll n;
ll ans = -1;
ll a[maxn][2],val[maxn];
set<ll> s[maxn];
void get(ll i){
vector<ll> v = ask(i);
a[i][0] = v[0],a[i][1] = v[1];
val[i] = a[i][0] + a[i][1];
}
void reshi(ll l,ll r){
if(l>r||(ans!=-1)) return;
ll mid = (l+r)/2;
get(mid);
if(val[mid]==0){
ans = mid;
return;
}
ll sum = val[mid];
auto it = s[sum].upper_bound(mid);
ll lok = 1,rok = 1;
if(it!=s[sum].end()){
ll j = *it;
if(j>r&&a[j][0]-a[mid][0]==0) rok = 0;
}
if(it!=s[sum].begin()){
it--;
ll j = *it;
if(j<l&&a[mid][0]-a[j][0]==0) lok = 0;
}
s[sum].insert(mid);
if(lok) reshi(l,mid-1);
if(rok) reshi(mid+1,r);
}
int find_best(int N){
n = N;
reshi(0,n-1);
return ans;
}
/*
8
3 1 3 2 3 3 2 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
2 |
Correct |
6 ms |
9808 KB |
Output is correct |
3 |
Correct |
6 ms |
9820 KB |
Output is correct |
4 |
Correct |
5 ms |
9692 KB |
Output is correct |
5 |
Correct |
5 ms |
9808 KB |
Output is correct |
6 |
Correct |
5 ms |
9700 KB |
Output is correct |
7 |
Correct |
5 ms |
9688 KB |
Output is correct |
8 |
Correct |
5 ms |
9828 KB |
Output is correct |
9 |
Correct |
7 ms |
9680 KB |
Output is correct |
10 |
Correct |
5 ms |
9760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
5 ms |
9820 KB |
Output is correct |
3 |
Correct |
5 ms |
9692 KB |
Output is correct |
4 |
Correct |
6 ms |
9808 KB |
Output is correct |
5 |
Correct |
5 ms |
9800 KB |
Output is correct |
6 |
Correct |
5 ms |
9696 KB |
Output is correct |
7 |
Correct |
6 ms |
9696 KB |
Output is correct |
8 |
Correct |
6 ms |
9808 KB |
Output is correct |
9 |
Correct |
5 ms |
9688 KB |
Output is correct |
10 |
Correct |
5 ms |
9708 KB |
Output is correct |
11 |
Correct |
7 ms |
10200 KB |
Output is correct |
12 |
Correct |
5 ms |
9680 KB |
Output is correct |
13 |
Correct |
9 ms |
10712 KB |
Output is correct |
14 |
Correct |
6 ms |
9704 KB |
Output is correct |
15 |
Correct |
10 ms |
10080 KB |
Output is correct |
16 |
Correct |
23 ms |
11736 KB |
Output is correct |
17 |
Correct |
6 ms |
9688 KB |
Output is correct |
18 |
Correct |
49 ms |
12072 KB |
Output is correct |
19 |
Correct |
5 ms |
9700 KB |
Output is correct |
20 |
Correct |
14 ms |
10100 KB |
Output is correct |
21 |
Correct |
18 ms |
10580 KB |
Output is correct |
22 |
Correct |
7 ms |
9940 KB |
Output is correct |
23 |
Correct |
5 ms |
9680 KB |
Output is correct |
24 |
Correct |
5 ms |
9680 KB |
Output is correct |
25 |
Correct |
21 ms |
11028 KB |
Output is correct |
26 |
Correct |
16 ms |
10960 KB |
Output is correct |
27 |
Correct |
7 ms |
9800 KB |
Output is correct |
28 |
Correct |
35 ms |
11896 KB |
Output is correct |
29 |
Correct |
29 ms |
11672 KB |
Output is correct |
30 |
Correct |
40 ms |
12128 KB |
Output is correct |
31 |
Correct |
6 ms |
9708 KB |
Output is correct |
32 |
Correct |
8 ms |
10364 KB |
Output is correct |
33 |
Correct |
5 ms |
9680 KB |
Output is correct |
34 |
Correct |
21 ms |
10436 KB |
Output is correct |
35 |
Correct |
8 ms |
10076 KB |
Output is correct |
36 |
Correct |
16 ms |
10184 KB |
Output is correct |
37 |
Correct |
6 ms |
9800 KB |
Output is correct |
38 |
Correct |
5 ms |
9680 KB |
Output is correct |
39 |
Correct |
22 ms |
10824 KB |
Output is correct |
40 |
Correct |
45 ms |
12172 KB |
Output is correct |
41 |
Correct |
26 ms |
11112 KB |
Output is correct |
42 |
Correct |
32 ms |
11092 KB |
Output is correct |
43 |
Correct |
24 ms |
10964 KB |
Output is correct |
44 |
Correct |
26 ms |
10696 KB |
Output is correct |
45 |
Correct |
17 ms |
10444 KB |
Output is correct |
46 |
Correct |
7 ms |
9696 KB |
Output is correct |
47 |
Correct |
25 ms |
10676 KB |
Output is correct |
48 |
Correct |
20 ms |
11532 KB |
Output is correct |
49 |
Correct |
9 ms |
9824 KB |
Output is correct |
50 |
Correct |
54 ms |
12128 KB |
Output is correct |
51 |
Correct |
21 ms |
10684 KB |
Output is correct |
52 |
Correct |
6 ms |
9684 KB |
Output is correct |
53 |
Correct |
8 ms |
10128 KB |
Output is correct |
54 |
Correct |
22 ms |
10712 KB |
Output is correct |
55 |
Correct |
5 ms |
9704 KB |
Output is correct |
56 |
Correct |
40 ms |
12172 KB |
Output is correct |
57 |
Correct |
37 ms |
11452 KB |
Output is correct |
58 |
Correct |
32 ms |
11416 KB |
Output is correct |
59 |
Correct |
26 ms |
11092 KB |
Output is correct |
60 |
Correct |
26 ms |
11016 KB |
Output is correct |
61 |
Correct |
6 ms |
10076 KB |
Output is correct |
62 |
Correct |
5 ms |
9680 KB |
Output is correct |
63 |
Correct |
8 ms |
10056 KB |
Output is correct |
64 |
Correct |
6 ms |
9936 KB |
Output is correct |
65 |
Correct |
7 ms |
9800 KB |
Output is correct |
66 |
Correct |
5 ms |
9824 KB |
Output is correct |
67 |
Correct |
7 ms |
9684 KB |
Output is correct |
68 |
Correct |
6 ms |
9692 KB |
Output is correct |
69 |
Correct |
5 ms |
9808 KB |
Output is correct |
70 |
Correct |
5 ms |
9684 KB |
Output is correct |
71 |
Correct |
43 ms |
12140 KB |
Output is correct |
72 |
Correct |
9 ms |
10704 KB |
Output is correct |
73 |
Correct |
46 ms |
12232 KB |
Output is correct |
74 |
Correct |
42 ms |
12128 KB |
Output is correct |
75 |
Correct |
6 ms |
10064 KB |
Output is correct |
76 |
Correct |
44 ms |
12104 KB |
Output is correct |
77 |
Correct |
44 ms |
12204 KB |
Output is correct |
78 |
Correct |
10 ms |
10728 KB |
Output is correct |
79 |
Correct |
29 ms |
11936 KB |
Output is correct |
80 |
Correct |
53 ms |
12104 KB |
Output is correct |
81 |
Correct |
45 ms |
12188 KB |
Output is correct |
82 |
Correct |
61 ms |
12188 KB |
Output is correct |
83 |
Correct |
7 ms |
10064 KB |
Output is correct |
84 |
Correct |
39 ms |
12128 KB |
Output is correct |
85 |
Correct |
40 ms |
12144 KB |
Output is correct |
86 |
Correct |
11 ms |
10576 KB |
Output is correct |
87 |
Correct |
10 ms |
10320 KB |
Output is correct |
88 |
Correct |
9 ms |
10440 KB |
Output is correct |
89 |
Correct |
9 ms |
10448 KB |
Output is correct |
90 |
Correct |
7 ms |
10064 KB |
Output is correct |
91 |
Correct |
8 ms |
10216 KB |
Output is correct |
92 |
Correct |
5 ms |
9808 KB |
Output is correct |
93 |
Correct |
9 ms |
10320 KB |
Output is correct |
94 |
Correct |
8 ms |
10396 KB |
Output is correct |
95 |
Correct |
10 ms |
10576 KB |
Output is correct |
96 |
Correct |
8 ms |
10344 KB |
Output is correct |
97 |
Correct |
5 ms |
9708 KB |
Output is correct |