fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 2e5 + 5;
  4. int n, a[maxn], pre[maxn], suf[maxn], maxx, cnt;
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. if(fopen("tree.inp", "r"))
  10. {
  11. freopen("tree.inp", "r", stdin);
  12. freopen("tree.out", "w", stdout);
  13. }
  14. cin >> n;
  15. for(int i = 1; i <= n; i++) cin >> a[i];
  16. pre[1] = 1;
  17. suf[n] = 1;
  18. for(int i = 2; i <= n; i++)
  19. {
  20. if(a[i] > a[i - 1]) pre[i] = pre[i - 1] + 1;
  21. else pre[i] = 1;
  22. maxx = max(maxx, pre[i]);
  23. }
  24. for(int i = n - 1; i >= 1; i--)
  25. {
  26. if(a[i] < a[i + 1]) suf[i] = suf[i + 1] + 1;
  27. else suf[i] = 1;
  28. }
  29. for(int i = 2; i < n; i++)
  30. {
  31. if(a[i - 1] < a[i + 1]) maxx = max(maxx, pre[i - 1] + suf[i + 1]);
  32. }
  33. for(int i = 1; i <= n; i++)
  34. {
  35. if(pre[i] == maxx && maxx != n) cnt++;
  36. else if(i >= 2 && i < n && a[i - 1] < a[i + 1] && pre[i - 1] + suf[i + 1] == maxx) cnt++;
  37. }
  38. cout << cnt;
  39. return 0;
  40. }
Success #stdin #stdout 0s 5352KB
stdin
6
1 2 3 4 5 6
stdout
Standard output is empty