tien_noob

Po (COCI)

Feb 13th, 2021 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. using namespace std;
  6. const int N = 1e5;
  7. int a[N+1], ans[N+1], n;
  8. void read()
  9. {
  10.    cin >> n;
  11.    for (int i = 1; i <= n; ++ i)
  12.    {
  13.        cin >> a[i];
  14.    }
  15. }
  16. void solve()
  17. {
  18.     vector<int> sol;
  19.     ans[0] = 0;
  20.     for (int i = 1; i <= n; ++ i)
  21.     {
  22.         ans[i] = ans[i-1];
  23.         if (a[i] == 0)
  24.         {
  25.             sol.clear();
  26.             continue;
  27.         }
  28.         else
  29.         {
  30.             while (!sol.empty() && a[sol.back()] > a[i])
  31.             {
  32.                 sol.pop_back();
  33.             }
  34.             if (sol.empty() || a[sol.back()] < a[i])
  35.             {
  36.                 sol.push_back(i);
  37.                 ++ans[i];
  38.             }
  39.         }
  40.     }
  41.     cout << ans[n];
  42. }
  43. int main()
  44. {
  45.     ios_base::sync_with_stdio(false);
  46.     cin.tie(nullptr);
  47.     read();
  48.     solve();
  49. }
  50.  
Add Comment
Please, Sign In to add comment