Advertisement
Josif_tepe

Untitled

Sep 25th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     ios_base::sync_with_stdio(false);
  8.     int n;
  9.     cin >> n;
  10.     vector<int> v(n + 1), next_value(n + 1);
  11.     vector<pair<int, int> > v2;
  12.     for(int i = 1; i <= n; i++) {
  13.         cin >> v[i];
  14.         v2.push_back(make_pair(v[i], i));
  15.         if(v[i] > 1) {
  16.             next_value[v[i] - 1] = i;
  17.         }
  18.     }
  19.     sort(v2.begin(), v2.end());
  20.     int rounds = 1;
  21.     for(int i = 1; i < n; i++) {
  22.         if(next_value[i] < v2[i - 1].second) {
  23.             ++rounds;
  24.         }
  25.     }
  26.     cout << rounds << endl;
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement