Ankit_132

B

Aug 30th, 2023
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         int n;
  13.         cin>>n;
  14.  
  15.         vector<int> a(n);
  16.         for(auto &e: a)
  17.             cin>>e;
  18.  
  19.         vector<int> pos(n+1);
  20.         for(int i=0; i<n; i++)
  21.             pos[a[i]] = i;
  22.  
  23.         int ans = 0;
  24.  
  25.         for(int i=1; i<n; i++)
  26.             ans += pos[i+1] < pos[i];
  27.  
  28.         cout<<ans<<"\n";
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment