-
Notifications
You must be signed in to change notification settings - Fork 1
/
The Ant Man
83 lines (75 loc) · 1.41 KB
/
The Ant Man
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Author : jignesh1604
* Link : https://www.hackerearth.com/problem/algorithm/the-ant-man-73f27925/
*/
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define sz size()
#define ff first
#define ss second
#define ll long long int
#define ld long double
#define bp __builtin_popcountll
#define FOR(i,a,b) for(i=a;i<b;i++)
#define ROR(i,a,b) for(i=a;i>b;i--)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define RORE(i,a,b) for(i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
const ll M=1e9+7;
bool isprime(ll n)
{
for(ll i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return false;
}
return true;
}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
if(a.first<b.first)
return true;
else
return false;
}
// fflush(stdout)
int main()
{
FAST;
ll n,i,j,ans=0,x;
cin>>n;
queue<ll> a,b;
FOR(i,0,n)
{
cin>>x;
a.push(x);
}
FOR(i,0,n)
{
cin>>x;
b.push(x);
}
map<ll,ll> mp;
while(!a.empty())
{
if(mp[a.front()]==1)
{
a.pop();
}
else if(a.front()==b.front())
{
a.pop();
b.pop();
}
else
{
ans++;
mp[b.front()]=1;
b.pop();
}
}
cout<<ans<<"\n";
}