-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncreasing Subsequence.cpp
More file actions
38 lines (38 loc) · 892 Bytes
/
Increasing Subsequence.cpp
File metadata and controls
38 lines (38 loc) · 892 Bytes
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
#include<bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
const int mod=1e9+7;
const int inf=1e9+7;
int main(){
boost;
int n;
cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++)cin>>v[i];
map<int,int>M;
set<int>s;
s.insert(v[0]);
M[v[0]]=1;
for(int i=1;i<n;i++){
auto ip=s.upper_bound(v[i]);
if(ip==s.end()){
auto x=ip;
x--;
if(*x!=v[i]) M[v[i]]=M[*x]+1;
s.insert(v[i]);
}else if(ip==s.begin()){
// M.erase(*ip);
s.erase(*ip);
s.insert(v[i]);
M[v[i]]=1;
}else{
auto x=ip;
x--;
if(*x!=v[i]) M[v[i]]=M[*ip],s.erase(ip);
s.insert(v[i]);
}
}
auto it=s.end();
it--;
cout<<M[*it]<<endl;
}