File tree 1 file changed +9
-18
lines changed 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change @@ -4,34 +4,25 @@ using namespace std;
4
4
using ll = int64_t ;
5
5
using ff = long double ;
6
6
7
- int N, M;
8
- vector<int > A;
9
-
10
- array<int ,2 > solve (int tl, int tr) {
11
- if (tr - tl == 2 ) {
12
- if (A[tl] < A[tl+1 ]) return { tl, tl+1 };
13
- else return { tl+1 , tl };
14
- }
15
- int tm = (tl + tr) >> 1 ;
16
- auto lhs = solve (tl, tm );
17
- auto rhs = solve (tm , tr);
18
- int l = lhs[1 ], r = rhs[1 ];
19
- if (A[l] < A[r]) return { l, r };
20
- else return { r, l };
21
- }
22
-
23
7
int main () {
24
8
ios_base::sync_with_stdio (false );
25
9
cin.tie (0 ); cout.tie (0 );
26
10
11
+ int N, M;
12
+ vector<int > A;
13
+
27
14
cin >> N;
28
15
M = 1 << N;
29
16
A.assign (M, 0 );
30
17
for (int i = 0 ; i < M; ++i) {
31
18
cin >> A[i];
32
19
}
33
- int ans = solve (0 , M)[0 ] + 1 ;
34
- cout << ans << endl;
20
+
21
+ M /= 2 ;
22
+ auto l = distance (A.begin (), max_element (A.begin (), A.begin () + M));
23
+ auto r = distance (A.begin (), max_element (A.begin () + M, A.end ()));
24
+ int ans = (A[l] < A[r]) ? l : r;
25
+ cout << (ans+1 ) << endl;
35
26
36
27
return 0 ;
37
28
}
You can’t perform that action at this time.
0 commit comments