Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- // cout << fixed << setprecision(50);
- int n, k = 0;
- cin >> n;
- vector <int> v1(n);
- vector <int> v2(n);
- vector <int> v3(n);
- for(int i = n - 1; i >= 0; i--) {
- cin >> v1[i];
- }
- for(int i = n - 1; i >= 0; i--) {
- cin >> v2[i];
- v3[v2[i]] = i;
- }
- int t, pos;
- for(int i = 0; i < n; i++) {
- if(v1[i] != v2[i]) {
- pos = v3[v1[i]];
- for(int f = pos; f > i; f--) {
- swap(v3[v2[f]], v3[v2[f-1]]);
- swap(v2[f], v2[f-1]);
- }
- k++;
- }
- }
- cout << k;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement