Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N = 2000000;
- int a[N];
- int f(int l, int r, int b) {
- if (l + 1 < r) {
- int m = (l + r) / 2;
- l = f(l, m, 0);
- r = f(m + 1, r, 0);
- }
- if (b == 0) {
- if (a[l] > a[r]) return l;
- return r;
- }
- else {
- if (a[l] > a[r]) return r;
- return l;
- }
- }
- signed main() {
- // freopen("in" , "r", stdin );
- cin.tie(0)->sync_with_stdio(0);
- int n; cin >> n;
- n = (1 << n);
- for (int i = 1; i <= n; i++) {
- cin >> a[i];
- }
- cout << f(1, n, 1) << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement