Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <stack>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> A(n), B(n), idx(n + 1);
- for(int i = 0; i < n; i++) {
- cin >> A[i];
- idx[A[i]] = i;
- }
- for(int i = 0; i < n; i++) {
- cin >> B[i];
- }
- int res = 0;
- for(int i = 0; i < n; i++) {
- if(A[i] != B[i]) {
- res++;
- int tmp = idx[B[i]], tmp2 = A[i];
- swap(A[i], A[tmp]);
- idx[A[i]] = i;
- idx[tmp2] = tmp;
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment