Josif_tepe

Untitled

Feb 25th, 2026
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <stack>
  5. //#include <bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. int main()
  9. {
  10.     ios_base::sync_with_stdio(false);
  11.     int n;
  12.     cin >> n;
  13.    
  14.     vector<int> A(n), B(n), idx(n + 1);
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> A[i];
  17.         idx[A[i]] = i;
  18.     }
  19.    
  20.     for(int i = 0; i < n; i++) {
  21.         cin >> B[i];
  22.     }
  23.    
  24.     int res = 0;
  25.     for(int i = 0; i < n; i++) {
  26.         if(A[i] != B[i]) {
  27.             res++;
  28.            
  29.             int tmp = idx[B[i]], tmp2 = A[i];
  30.             swap(A[i], A[tmp]);
  31.             idx[A[i]] = i;
  32.             idx[tmp2] = tmp;
  33.         }
  34.     }
  35.    
  36.     cout << res << endl;
  37.    
  38.    
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment