// {{{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 int(1e6)
vector<int> ask(int i);
#ifdef DBG
int n; vector<int> arr;
int pre[N][10], suf[N][10];
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++;
// assert(l == pre[i][arr[i]-1]);
// assert(r == suf[i][arr[i]-1]);
// return vector<int>{l,r};
return vector<int>{pre[i][arr[i]-1],suf[i][arr[i]-1]};
}
#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(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--;
}
if(right(l) == right(r)) return;
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;
for(int i=0;i<n;i++) {
pre[i][arr[i]] = 1;
suf[i][arr[i]] = 1;
}
for(int i=1;i<n;i++) for(int v=0;v<10;v++)pre[i][v]+=pre[i-1][v];
for(int i=n-2;~i;i--)for(int v=0;v<10;v++)suf[i][v]+=suf[i+1][v];
for(int i=0;i<n;i++)for(int v=1;v<10;v++)pre[i][v]+=pre[i][v-1], suf[i][v]+=suf[i][v-1];
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;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
448 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
0 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
448 KB |
Output is correct |
10 |
Correct |
0 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
1 ms |
700 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
448 KB |
Output is correct |
8 |
Correct |
1 ms |
444 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
480 KB |
Output is correct |
11 |
Correct |
1 ms |
500 KB |
Output is correct |
12 |
Correct |
1 ms |
452 KB |
Output is correct |
13 |
Correct |
3 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
452 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
16 ms |
2756 KB |
Output is correct |
17 |
Correct |
0 ms |
452 KB |
Output is correct |
18 |
Correct |
25 ms |
2716 KB |
Output is correct |
19 |
Correct |
0 ms |
448 KB |
Output is correct |
20 |
Correct |
6 ms |
1012 KB |
Output is correct |
21 |
Correct |
10 ms |
1456 KB |
Output is correct |
22 |
Correct |
2 ms |
752 KB |
Output is correct |
23 |
Correct |
0 ms |
452 KB |
Output is correct |
24 |
Correct |
0 ms |
608 KB |
Output is correct |
25 |
Correct |
10 ms |
1684 KB |
Output is correct |
26 |
Correct |
13 ms |
1784 KB |
Output is correct |
27 |
Correct |
1 ms |
656 KB |
Output is correct |
28 |
Correct |
30 ms |
1816 KB |
Output is correct |
29 |
Correct |
15 ms |
2096 KB |
Output is correct |
30 |
Correct |
26 ms |
2456 KB |
Output is correct |
31 |
Correct |
1 ms |
704 KB |
Output is correct |
32 |
Correct |
2 ms |
1064 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
1064 KB |
Output is correct |
35 |
Correct |
1 ms |
764 KB |
Output is correct |
36 |
Correct |
5 ms |
1176 KB |
Output is correct |
37 |
Correct |
1 ms |
764 KB |
Output is correct |
38 |
Correct |
1 ms |
608 KB |
Output is correct |
39 |
Correct |
9 ms |
1092 KB |
Output is correct |
40 |
Correct |
18 ms |
1976 KB |
Output is correct |
41 |
Correct |
14 ms |
2104 KB |
Output is correct |
42 |
Correct |
12 ms |
2016 KB |
Output is correct |
43 |
Correct |
12 ms |
1392 KB |
Output is correct |
44 |
Correct |
9 ms |
1452 KB |
Output is correct |
45 |
Correct |
6 ms |
1140 KB |
Output is correct |
46 |
Correct |
1 ms |
448 KB |
Output is correct |
47 |
Correct |
9 ms |
1324 KB |
Output is correct |
48 |
Correct |
15 ms |
2576 KB |
Output is correct |
49 |
Correct |
2 ms |
1244 KB |
Output is correct |
50 |
Correct |
20 ms |
2744 KB |
Output is correct |
51 |
Correct |
9 ms |
1572 KB |
Output is correct |
52 |
Correct |
1 ms |
488 KB |
Output is correct |
53 |
Correct |
1 ms |
508 KB |
Output is correct |
54 |
Correct |
8 ms |
1524 KB |
Output is correct |
55 |
Correct |
1 ms |
448 KB |
Output is correct |
56 |
Correct |
21 ms |
3040 KB |
Output is correct |
57 |
Correct |
17 ms |
2616 KB |
Output is correct |
58 |
Correct |
16 ms |
1852 KB |
Output is correct |
59 |
Correct |
11 ms |
2060 KB |
Output is correct |
60 |
Correct |
11 ms |
1500 KB |
Output is correct |
61 |
Correct |
1 ms |
512 KB |
Output is correct |
62 |
Correct |
1 ms |
452 KB |
Output is correct |
63 |
Correct |
1 ms |
772 KB |
Output is correct |
64 |
Correct |
1 ms |
508 KB |
Output is correct |
65 |
Correct |
1 ms |
708 KB |
Output is correct |
66 |
Correct |
2 ms |
444 KB |
Output is correct |
67 |
Correct |
3 ms |
448 KB |
Output is correct |
68 |
Correct |
2 ms |
452 KB |
Output is correct |
69 |
Correct |
2 ms |
444 KB |
Output is correct |
70 |
Correct |
2 ms |
448 KB |
Output is correct |
71 |
Correct |
21 ms |
2160 KB |
Output is correct |
72 |
Correct |
2 ms |
1124 KB |
Output is correct |
73 |
Correct |
22 ms |
2656 KB |
Output is correct |
74 |
Correct |
25 ms |
2588 KB |
Output is correct |
75 |
Correct |
1 ms |
460 KB |
Output is correct |
76 |
Correct |
19 ms |
1984 KB |
Output is correct |
77 |
Correct |
24 ms |
1884 KB |
Output is correct |
78 |
Correct |
3 ms |
1724 KB |
Output is correct |
79 |
Correct |
12 ms |
2408 KB |
Output is correct |
80 |
Correct |
21 ms |
2956 KB |
Output is correct |
81 |
Correct |
21 ms |
2108 KB |
Output is correct |
82 |
Correct |
25 ms |
2164 KB |
Output is correct |
83 |
Correct |
1 ms |
704 KB |
Output is correct |
84 |
Correct |
21 ms |
2556 KB |
Output is correct |
85 |
Correct |
30 ms |
2292 KB |
Output is correct |
86 |
Correct |
2 ms |
700 KB |
Output is correct |
87 |
Correct |
1 ms |
444 KB |
Output is correct |
88 |
Correct |
2 ms |
960 KB |
Output is correct |
89 |
Correct |
2 ms |
964 KB |
Output is correct |
90 |
Correct |
1 ms |
444 KB |
Output is correct |
91 |
Correct |
1 ms |
708 KB |
Output is correct |
92 |
Correct |
1 ms |
444 KB |
Output is correct |
93 |
Correct |
2 ms |
980 KB |
Output is correct |
94 |
Correct |
2 ms |
1264 KB |
Output is correct |
95 |
Correct |
2 ms |
1224 KB |
Output is correct |
96 |
Correct |
2 ms |
788 KB |
Output is correct |
97 |
Correct |
1 ms |
488 KB |
Output is correct |