GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Data-Structure_Algorithms_Coding/lcs.cpp at main · Sdccoding/Data-Structure_Algorithms_Coding

Expand file tree

/

lcs.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
94 lines (66 loc) · 1.34 KB
/

lcs.cpp

Copy path

File metadata and controls

94 lines (66 loc) · 1.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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;
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.