Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. // cout << fixed << setprecision(50);
  10.  
  11. int n, k = 0;
  12. cin >> n;
  13. vector <int> v1(n);
  14. vector <int> v2(n);
  15. vector <int> v3(n);
  16. for(int i = n - 1; i >= 0; i--) {
  17. cin >> v1[i];
  18. }
  19. for(int i = n - 1; i >= 0; i--) {
  20. cin >> v2[i];
  21. v3[v2[i]] = i;
  22. }
  23. int t, pos;
  24. for(int i = 0; i < n; i++) {
  25. if(v1[i] != v2[i]) {
  26. pos = v3[v1[i]];
  27. for(int f = pos; f > i; f--) {
  28. swap(v3[v2[f]], v3[v2[f-1]]);
  29. swap(v2[f], v2[f-1]);
  30. }
  31. k++;
  32. }
  33. }
  34. cout << k;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement