-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathtabara1.cpp
40 lines (38 loc) · 839 Bytes
/
tabara1.cpp
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
# include <cstdio>
# include <algorithm>
# define NR 30005
using namespace std;
int i,j,n,m,x,VV,ci,cs,mij,poz;
int ap[NR], a[NR], st[NR];
int main ()
{
freopen ("tabara1.in", "r", stdin);
freopen ("tabara1.out", "w", stdout);
scanf ("%d", &n);
for (i=1; i<=n; ++i)
{
scanf ("%d", &x);
ap[x]=i;
}
for (i=1; i<=n; ++i)
{
scanf ("%d", &x);
a[ap[x]]=i;
}
for (i=1; i<=n; ++i)
{
if (a[i]>st[VV]) st[++VV]=a[i];
else {
ci=1; cs=VV; poz=VV;
while (ci<=cs)
{
mij=(ci+cs)/2;
if (st[mij]<a[i]) ci=mij+1;
else cs=mij-1, poz=mij;
}
st[poz]=a[i];
}
}
printf ("%d\n", VV);
return 0;
}