#include <bits/stdc++.h>
const int inf = 1e9+900;
struct Node {
int left,right;
int val;
int l,r;
void inicializa(){
l=0;
r=+1e9+10000;
}
};
Node mem[12000000];
int cursor= 2;
int novonode(void){
if(cursor==12000000){
assert(0);
}
return cursor++;
}
int update(int t,int k,Node* v){
if(v==&mem[0])return 0;
int la=v->l,ra=v->r;
if(t<la||ra<t)return 0;
if(la==ra){
v->val=std::max(v->val,k);
return k;
}
int m = (la+ra)/2;
if(!v->left&&(t<la&&m<t)){
int k = novonode();
v->left=k;
mem[k].l=la;
mem[k].r=m;
}
if(!v->right&&(t<m+1&&ra<t)){
int k = novonode();
v->right=k;
mem[k].l=m+1;
mem[k].r=ra;
}
int a = update(t,k,&mem[v->left]);
int b = update(t,k,&mem[v->right]);
v->val=std::max((&mem[v->left])->val,(&mem[v->right])->val);
return v->val;
}
int query(int l,int r,Node* v){
int la=v->l,ra=v->r;
if(r<la||ra<l)return 0;
if(la>=l&&ra<=r){
return v->val;
}
int m = (la+ra)/2;
if(!v->left){
int k = novonode();
v->left=k;
mem[k].l=la;
mem[k].r=m;
}
if(!v->right){
int k = novonode();
v->right=k;
mem[k].l=m+1;
mem[k].r=ra;
}
int a = query(l,r,&mem[v->left]);
int b = query(l,r,&mem[v->right]);
return std::max(a,b);
}
const int val = 1e8;
Node sega,segb;
int main()
{
int N,T;
std::cin>>N>>T;
int array[N];for(auto&x:array)std::cin>>x;
int resp=0;
///Caso d=0
{
std::vector<int> vec;
for(int i=0;i!=N;++i){
int x=array[i];
auto it = std::lower_bound(vec.begin(),vec.end(),x);
if(it==vec.end()){
vec.push_back(x);
}else *it=x;
}
resp=vec.size();
}
///Caso d=T
{
sega.inicializa();
segb.inicializa();
for(int i=0;i!=N;++i){
int base = array[i];
int verdade = base - 1;
///Atualiza caso ele tenha adicionado
{
int futuro = verdade+T;
int val1 = query(0,verdade,&segb);
int val2 = query(0,futuro,&sega);
update(base,std::max(val1,val2)+1,&segb);
}
///Atualiza caso nao tenha adicionado
update(base,query(0,verdade,&sega)+1,&sega);
}
resp=std::max(resp,std::max(query(0,inf,&sega),query(0,inf,&segb)));
}
std::cout<<(resp)<<"\n";
}
Compilation message
glo.cpp: In function 'int update(int, int, Node*)':
glo.cpp:41:9: warning: unused variable 'a' [-Wunused-variable]
41 | int a = update(t,k,&mem[v->left]);
| ^
glo.cpp:42:9: warning: unused variable 'b' [-Wunused-variable]
42 | int b = update(t,k,&mem[v->right]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
722 ms |
179576 KB |
Output is correct |
2 |
Correct |
676 ms |
179768 KB |
Output is correct |
3 |
Correct |
682 ms |
179616 KB |
Output is correct |
4 |
Correct |
702 ms |
179808 KB |
Output is correct |
5 |
Correct |
409 ms |
98248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
57796 KB |
Output is correct |
2 |
Correct |
165 ms |
57876 KB |
Output is correct |
3 |
Correct |
167 ms |
57824 KB |
Output is correct |
4 |
Incorrect |
109 ms |
31232 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
293 ms |
97812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |