-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcs.cpp
More file actions
94 lines (66 loc) · 1.34 KB
/
lcs.cpp
File metadata and controls
94 lines (66 loc) · 1.34 KB
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
84
85
86
87
88
89
90
91
92
93
94
//Find LCS in terms of LIS,when 1 array has unique elemnts
//Find LIS in O(nlogn)
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pi pair<int,int>
#define JALDI ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
void so(vector<ll> &v)
{
sort(v.begin(),v.end());
}
int main()
{
JALDI;
ll n,m;
cin>>n>>m;
vector<ll>s(n),t(m);
for(ll i=0;i<n;i++)
cin>>s[i];
unordered_map<int,int>mp;
for(ll i=0;i<m;i++)
{
cin>>t[i];
mp[t[i]]=i;
}
for(ll i=0;i<n;i++)
{
if(mp.find(s[i])!=mp.end())
{
s[i]=mp[s[i]];
}
else
s[i]=-1;
}
vector<ll>tail;
for(ll i=0;i<n;i++)
{
if(s[i]==-1) continue;
else if(tail.size()==0)
{
tail.pb(s[i]);
}
else if(s[i]>=tail.back())
{
tail.pb(s[i]);
}
else if(s[i]<tail[0])
{
tail[0]=s[i];
}
else
{
auto it=lower_bound(tail.begin(),tail.end(),s[i]);
*it=s[i];
}
}
cout<<tail.size()<<endl;
return 0;
}