#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)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)){
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]);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
716 ms |
183184 KB |
Output is correct |
2 |
Correct |
711 ms |
183336 KB |
Output is correct |
3 |
Correct |
707 ms |
183328 KB |
Output is correct |
4 |
Correct |
708 ms |
183308 KB |
Output is correct |
5 |
Correct |
402 ms |
100004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
58692 KB |
Output is correct |
2 |
Correct |
186 ms |
58732 KB |
Output is correct |
3 |
Correct |
185 ms |
58776 KB |
Output is correct |
4 |
Incorrect |
110 ms |
31596 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
318 ms |
99632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |