-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12015.cpp
More file actions
55 lines (43 loc) · 1.14 KB
/
12015.cpp
File metadata and controls
55 lines (43 loc) · 1.14 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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int ST = 1<<20;
int seg[ST*2],N,A[ST];
vector<pair<int,int>> v;
bool cmp(pair<int,int> a, pair<int,int> b){
if(a.first == b.first) return a.second > b.second;
else return a.first < b.first;
}
void build(){
// for(int i=0 ; i<N ; i++) seg[i+ST] = v[i].first;
for(int i=ST-1 ; i>0 ; i--) seg[i] = max(seg[i*2], seg[i*2+1]);
}
void update(int idx, int val){
seg[idx] = val;
for(int i = idx/2 ; i>0 ; i/=2){
seg[i] = max(seg[i*2],seg[i*2+1]);
}
}
int findOpt(int n, int nl, int nr, int l, int r){
if(nl>r || nr<l) return 0;
if(l<=nl && nr <=r) return seg[n];
int mid = (nl+nr)/2;
return max(findOpt(n*2,nl,mid,l,r), findOpt(n*2+1,mid+1,nr,l,r));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> N;
for(int i=0 ; i<N ; i++){
cin >> A[i];
v.push_back({A[i],i});
}
sort(v.begin(),v.end(),cmp);
for(int i=0 ; i<N ; i++){
int opt = findOpt(1,0,ST-1,0,v[i].second)+1;
update(ST+v[i].second, opt);
}
cout << seg[1];
}