-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogresing.cpp
More file actions
60 lines (53 loc) · 1.25 KB
/
Copy pathprogresing.cpp
File metadata and controls
60 lines (53 loc) · 1.25 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
#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
int lis(vector<pair<int,int>> const& a)
{
int n = a.size();
const int INF = 1e5;
vector<pair<int,int>> d(n+1, {INF,INF});
//cout<<d[1].first<<" "<<d[1].second<<"\n";
d[0] = {-INF,-INF};
for (int i = 0; i < n; i++)
{
int l;// = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
int L=0,R=n;
while(L<=R){
int m=(L+R)/2;
if(a[i].first<d[m].first&&a[i].second<d[m].second){
R=m-1;
l=m;
}
else{
L=m+1;
}
}
//cout<<i<<" "<<l<<"\n";
if (d[l-1].ff <= a[i].ff&& d[l-1].ss <= a[i].ss&& d[l].ff >= a[i].ff&& d[l].ss >= a[i].ss)
d[l] = a[i];
}
int ans = 0;
for (int l = 0; l <= n; l++)
{
if (d[l] < (make_pair(INF,INF)))
ans = l;
}
return ans;
}
int main()
{
int t=1;
//cin>>t;
while(t--)
{
int n,x,y;
cin>>n;
vector<pair<int,int>>v;
for(int i=0;i<n;i++){
cin>>x>>y;
v.push_back({x,y});
}
cout<<lis(v)<<"\n";
}
}