Advertisement
Josif_tepe

Untitled

Sep 25th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 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.         next_value[v[i]] = i;
  15.     }
  16.     int rounds = 1;
  17.     int f = 1;
  18.     for(int i = 1; i <= n; i++) {
  19.         if(f > next_value[i]) {
  20.             ++rounds;
  21.         }
  22.         f = next_value[i];
  23.     }
  24.     cout << rounds << endl;
  25.  
  26.     return 0;
  27. }
  28. // 4 2 1 5 3
  29. // ind[4] = 1
  30. // ind[2] = 2
  31. // ind[1] = 3
  32. // ind[5] = 4
  33. // ind[3] = 5
  34.  
  35. // int f = 1;
  36. // int rounds = 1;
  37. //
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement