fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. const int N = 1e5 + 5;
  5. int pre[N];
  6. int res;
  7.  
  8. bool sorted(int x, int y) {
  9. return pre[y] - pre[x - 1] == 0;
  10. }
  11.  
  12. void f(int x, int y) {
  13. if (sorted(x, y)) {
  14. res = max(res, y - x + 1);
  15. return;
  16. }
  17. if (y == x + 1) {
  18. res = max(1LL, res);
  19. return;
  20. }
  21. f(x, (x + y) / 2);
  22. f((x + y) / 2 + 1, y);
  23. }
  24.  
  25. signed main() {
  26. ios_base::sync_with_stdio(0);
  27. cin.tie(0);
  28. int n;
  29. cin >> n;
  30. int a[n + 1];
  31. for (int i = 1; i <= n; ++i) cin >> a[i];
  32. pre[0] = pre[1] = 0;
  33. for (int i = 2; i <= n; ++i) pre[i] = pre[i - 1] + (a[i] < a[i - 1]);
  34. f(1, n);
  35. cout << res;
  36. return 0;
  37. }
Success #stdin #stdout 0s 5320KB
stdin
8
11 12 1 2 13 14
3 4
stdout
2