// {{{1
extern "C" int __lsan_is_turned_off() { return 1; };
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#ifdef DEBUG
#define dprintf(args...) fprintf(stderr,args)
#endif
#ifndef DEBUG
#define dprintf(args...) 42
#endif
#define ll long long
#define all(x) (x).begin(),(x).end()
#define mod int(1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
void sleep(int x) { this_thread::sleep_for(chrono::seconds(x)); }
struct { template<typename T> operator T() { T x; cin>>x; return x; } } in;
struct __rng {
mt19937_64 _rng;
__rng() {
ll ctime = chrono::high_resolution_clock::now().time_since_epoch().count();
_rng = mt19937_64(ctime);
}
ll randint(ll l, ll h) {
return uniform_int_distribution<int>(l,h)(_rng);
}
} rng;
// 1}}}
#define rank rank2
// #define DBG
#define N 200000
vector<int> ask(int i);
#ifdef DBG
int n; vector<int> arr;
int q=0;
vector<int> ask(int i) {
q++;
int l=0,r=0;
for(int j=0;j<i;j++)if(arr[j]<arr[i]) l++;
for(int j=i+1;j<n;j++)if(arr[j]<arr[i])r++;
return vector<int>{l,r};
}
#endif
int ans[N][2];
int best=-1;
void ask2(int i) {
if(best == i) return;
if(ans[i][0]+ans[i][1] == 0) {
auto x = ask(i);
ans[i][0] = x[0];
ans[i][1] = x[1];
if(ans[i][0]+ans[i][1] == 0) assert(best==-1), best &= i;
}
}
int rank(int i) {
ask2(i);
return ans[i][0]+ans[i][1];
}
int right(int i) {
ask2(i);
return ans[i][1];
}
// lower rank is more rare
void solve(int l, int r) {
if(best >= 0) return;
if(right(l) == right(r)) return;
if(r<l) return;
if(l==r) return void(rank(l));
while(rank(l) != rank(r)) {
while(rank(l) < rank(r)) l++;
while(rank(l) > rank(r)) r--;
}
int m=(l+r)/2;
solve(l,m);
solve(m,r);
}
int find_best(int n) {
solve(0, n-1);
assert(best >= 0);
return best;
}
#ifdef DBG
int main() {
n=in;arr.resize(n);for(auto&x:arr)x=in;
int ans = find_best(n);
printf("%d\n",ans);
printf("q=%d\n",q);
return arr[ans]!=1;
}
#endif
Compilation message
prize.cpp:22:73: warning: 'in' defined but not used [-Wunused-variable]
22 | struct { template<typename T> operator T() { T x; cin>>x; return x; } } in;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
448 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
448 KB |
Output is correct |
8 |
Correct |
0 ms |
448 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
0 ms |
704 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
0 ms |
448 KB |
Output is correct |
9 |
Correct |
0 ms |
448 KB |
Output is correct |
10 |
Correct |
0 ms |
472 KB |
Output is correct |
11 |
Correct |
2 ms |
1156 KB |
Output is correct |
12 |
Correct |
1 ms |
448 KB |
Output is correct |
13 |
Correct |
2 ms |
1028 KB |
Output is correct |
14 |
Correct |
1 ms |
448 KB |
Output is correct |
15 |
Correct |
3 ms |
1080 KB |
Output is correct |
16 |
Correct |
20 ms |
2492 KB |
Output is correct |
17 |
Correct |
0 ms |
448 KB |
Output is correct |
18 |
Correct |
19 ms |
2660 KB |
Output is correct |
19 |
Correct |
1 ms |
448 KB |
Output is correct |
20 |
Correct |
6 ms |
736 KB |
Output is correct |
21 |
Correct |
8 ms |
1412 KB |
Output is correct |
22 |
Correct |
2 ms |
788 KB |
Output is correct |
23 |
Correct |
1 ms |
448 KB |
Output is correct |
24 |
Correct |
0 ms |
448 KB |
Output is correct |
25 |
Correct |
11 ms |
1664 KB |
Output is correct |
26 |
Correct |
12 ms |
2232 KB |
Output is correct |
27 |
Correct |
1 ms |
716 KB |
Output is correct |
28 |
Correct |
20 ms |
2828 KB |
Output is correct |
29 |
Correct |
15 ms |
2008 KB |
Output is correct |
30 |
Correct |
32 ms |
2088 KB |
Output is correct |
31 |
Correct |
1 ms |
448 KB |
Output is correct |
32 |
Correct |
2 ms |
776 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
1480 KB |
Output is correct |
35 |
Correct |
1 ms |
496 KB |
Output is correct |
36 |
Correct |
6 ms |
1664 KB |
Output is correct |
37 |
Correct |
1 ms |
496 KB |
Output is correct |
38 |
Correct |
0 ms |
628 KB |
Output is correct |
39 |
Correct |
8 ms |
1584 KB |
Output is correct |
40 |
Correct |
30 ms |
2020 KB |
Output is correct |
41 |
Correct |
11 ms |
1860 KB |
Output is correct |
42 |
Correct |
12 ms |
1476 KB |
Output is correct |
43 |
Correct |
11 ms |
1608 KB |
Output is correct |
44 |
Correct |
13 ms |
1408 KB |
Output is correct |
45 |
Correct |
8 ms |
1380 KB |
Output is correct |
46 |
Correct |
1 ms |
860 KB |
Output is correct |
47 |
Correct |
8 ms |
1628 KB |
Output is correct |
48 |
Correct |
16 ms |
2388 KB |
Output is correct |
49 |
Correct |
2 ms |
800 KB |
Output is correct |
50 |
Correct |
25 ms |
1988 KB |
Output is correct |
51 |
Correct |
10 ms |
1820 KB |
Output is correct |
52 |
Correct |
1 ms |
484 KB |
Output is correct |
53 |
Correct |
1 ms |
504 KB |
Output is correct |
54 |
Correct |
12 ms |
1552 KB |
Output is correct |
55 |
Correct |
0 ms |
448 KB |
Output is correct |
56 |
Correct |
26 ms |
2820 KB |
Output is correct |
57 |
Correct |
15 ms |
1788 KB |
Output is correct |
58 |
Correct |
16 ms |
2064 KB |
Output is correct |
59 |
Correct |
13 ms |
1984 KB |
Output is correct |
60 |
Correct |
11 ms |
1716 KB |
Output is correct |
61 |
Correct |
1 ms |
504 KB |
Output is correct |
62 |
Correct |
0 ms |
452 KB |
Output is correct |
63 |
Correct |
1 ms |
500 KB |
Output is correct |
64 |
Correct |
1 ms |
500 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
2 ms |
344 KB |
Output is correct |
67 |
Correct |
2 ms |
344 KB |
Output is correct |
68 |
Correct |
2 ms |
456 KB |
Output is correct |
69 |
Correct |
2 ms |
344 KB |
Output is correct |
70 |
Correct |
2 ms |
344 KB |
Output is correct |
71 |
Correct |
24 ms |
2764 KB |
Output is correct |
72 |
Correct |
2 ms |
1400 KB |
Output is correct |
73 |
Correct |
26 ms |
2088 KB |
Output is correct |
74 |
Correct |
29 ms |
2076 KB |
Output is correct |
75 |
Correct |
1 ms |
976 KB |
Output is correct |
76 |
Correct |
22 ms |
2208 KB |
Output is correct |
77 |
Partially correct |
35 ms |
2028 KB |
Partially correct - number of queries: 5025 |
78 |
Correct |
2 ms |
1088 KB |
Output is correct |
79 |
Correct |
12 ms |
2652 KB |
Output is correct |
80 |
Correct |
25 ms |
2444 KB |
Output is correct |
81 |
Correct |
21 ms |
2688 KB |
Output is correct |
82 |
Correct |
26 ms |
2628 KB |
Output is correct |
83 |
Correct |
1 ms |
960 KB |
Output is correct |
84 |
Correct |
23 ms |
2396 KB |
Output is correct |
85 |
Correct |
32 ms |
1932 KB |
Output is correct |
86 |
Correct |
2 ms |
956 KB |
Output is correct |
87 |
Correct |
1 ms |
448 KB |
Output is correct |
88 |
Correct |
2 ms |
956 KB |
Output is correct |
89 |
Correct |
2 ms |
956 KB |
Output is correct |
90 |
Correct |
1 ms |
448 KB |
Output is correct |
91 |
Correct |
1 ms |
700 KB |
Output is correct |
92 |
Correct |
1 ms |
444 KB |
Output is correct |
93 |
Correct |
2 ms |
964 KB |
Output is correct |
94 |
Correct |
2 ms |
744 KB |
Output is correct |
95 |
Correct |
2 ms |
1328 KB |
Output is correct |
96 |
Correct |
2 ms |
776 KB |
Output is correct |
97 |
Correct |
1 ms |
472 KB |
Output is correct |