Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef int64_t lld;
- typedef uint64_t llu;
- typedef long double llf;
- #define PB push_back
- #define ALL(x) begin(x), end(x)
- #define WC(x) while(x--)
- #define FF first
- #define SS second
- const int N = 3000000 + 5;
- int a[N], b[N], pos[N];
- int get_array(int[]);
- int main(){
- int n = get_array(a);
- int m = get_array(b);
- if(n != m){
- puts("-1");
- return 0;
- }
- for(int i=0;i<n;i++) pos[b[i]] = i;
- int ans = 0;
- for(int i=0;i<m;i++){
- if(b[i]==a[i]) continue;
- int x = i, y = pos[a[i]];
- pos[b[x]] = y; pos[b[y]] = x;
- swap(b[x], b[y]);
- ans ++;
- }
- printf("%d\n", ans);
- return 0;
- }
- int get_array(int arr[]){
- int p = 0;
- while(true){
- int x = 0;
- char c = getchar_unlocked();
- if(c == '\n') return 0;
- while(c == ' ') c=getchar_unlocked();
- while(isdigit(c)){
- x = x*10+c-'0';
- c = getchar_unlocked();
- }
- arr[p++] = x;
- if(c == '\n') break;
- }
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement