#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define int long long
const int N=5e5+5;
int n,k,ans,res,a[N];
int f[N];
int st[4*N];
int mod = 1e9;
map <int ,int > mp;
void update (int id , int l, int r ,int pos ,int val){
if(l> pos || r < pos){
return;
}
if (l==r){
st[id] = val;
return;
}
int m=(l+r)/2;
update(id *2 , l , m , pos , val);
update (id*2 +1 , m+1 , r , pos , val);
st[id] =max ( st[id*2],st[id*2 +1]);
}
int get(int id , int l ,int r ,int u , int v){
if ( v < l || u >r ){
return 0;
}
if(u<= l && r <=v){
return st[id];
}
int m = (l+r)/2;
return max(get(id*2 , l ,m, u ,v),
get(id*2+1 , m+1 , r , u ,v));
}
signed main (){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(int i=1; i<=n;i++){
cin>>a[i];
mp[a[i]]=1 ;
}
int m=0;
for(auto v : mp){
mp[v.fi]=++m;
}
for(int i=1 ; i<=n;i++){
a[i]= mp[a[i]];
m=max(m,a[i]);
}
update(1 ,1 ,n, a[1] , 1);
for(int i=2 ; i<=n;i++){
// f[a[i]]=1;
update( 1,1 ,n ,a[i],1);
// for(int j=1 ; j<a[i] ; j++){
// f[a[i]]= max( f[a[i]] ,f[j] +1);
// }
int ad = get (1 ,1 ,n,1 , a[i]-1)+1;
update(1,1 ,n , a[i] , ad);
}
cout<<get(1,1,n,1,n);
// for(int i=1 ; i<=n;i++) cout<<a[i]<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
259 ms |
20560 KB |
Output is correct |
2 |
Correct |
258 ms |
20384 KB |
Output is correct |
3 |
Correct |
235 ms |
20392 KB |
Output is correct |
4 |
Correct |
231 ms |
20560 KB |
Output is correct |
5 |
Correct |
110 ms |
11344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
5460 KB |
Output is correct |
2 |
Correct |
45 ms |
5468 KB |
Output is correct |
3 |
Correct |
45 ms |
5468 KB |
Output is correct |
4 |
Incorrect |
24 ms |
3100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
10268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |