#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int maxn = 3e5 + 10, inf = 2e9;
int n, d;
int a[maxn];
int dp[maxn];
int loga[maxn];
void saz(){
vector <int> s;
for(int i = 1; i <= n; i++){
s.push_back(a[i]);
}
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
for(int i = 1; i <= n; i++){
a[i] = s.end() - lower_bound(s.begin(), s.end(), a[i]);
// cout << a[i] << ' ';
}
// cout << endl;
}
void update(int x, int val){
for(++x; x < maxn; x += x & -x) loga[x] = max(loga[x], val);
}
int query(int x){
int ret = 0;
for(x; x > 0; x -= x & -x) ret = max(ret, loga[x]);
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> d;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
saz();
int naj = 0;
for(int i = n; i >= 1; i--){
dp[i] = query(a[i]) + 1;
update(a[i], dp[i]);
naj = max(naj, dp[i]);
// cout << i << ' ' << dp[i] << endl;
}
cout << naj;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |