This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
const int inf = 1e9+900;
struct Node {
Node* left,*right;
int val;
int l,r;
void inicializa(){
l=0;
r=+1e9+10000;
}
};
Node* novonode(void){
Node* x = (Node*)calloc(sizeof(Node),1);
return x;
}
int update(int t,int k,Node* v){
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){
Node* k = novonode();
v->left=k;
k->l=la;
k->r=m;
}
if(!v->right){
Node* k = novonode();
v->right=k;
k->l=m+1;
k->r=ra;
}
int a = update(t,k,v->left);
int b = update(t,k,v->right);
v->val=std::max(v->left->val,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){
Node* k = novonode();
v->left=k;
k->l=la;
k->r=m;
}
if(!v->right){
Node* k = novonode();
v->right=k;
k->l=m+1;
k->r=ra;
}
int a = query(l,r,v->left);
int b = query(l,r,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 (stderr)
glo.cpp: In function 'int update(int, int, Node*)':
glo.cpp:36:9: warning: unused variable 'a' [-Wunused-variable]
36 | int a = update(t,k,v->left);
| ^
glo.cpp:37:9: warning: unused variable 'b' [-Wunused-variable]
37 | int b = update(t,k,v->right);
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |