Submission #493770

# Submission time Handle Problem Language Result Execution time Memory
493770 2021-12-13T00:14:00 Z Deepesson Global Warming (CEOI18_glo) C++17
48 / 100
584 ms 262148 KB
#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

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
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 8 ms 5580 KB Output is correct
20 Correct 7 ms 5288 KB Output is correct
21 Correct 7 ms 4972 KB Output is correct
22 Correct 9 ms 4044 KB Output is correct
23 Correct 5 ms 2508 KB Output is correct
24 Correct 6 ms 2636 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 584 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 277 ms 146820 KB Output is correct
2 Correct 285 ms 146868 KB Output is correct
3 Correct 271 ms 146884 KB Output is correct
4 Correct 150 ms 78364 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 93 ms 10076 KB Output is correct
7 Correct 193 ms 101444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 511 ms 253564 KB Output is correct
2 Correct 475 ms 253436 KB Output is correct
3 Runtime error 581 ms 262148 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 8 ms 5580 KB Output is correct
20 Correct 7 ms 5288 KB Output is correct
21 Correct 7 ms 4972 KB Output is correct
22 Correct 9 ms 4044 KB Output is correct
23 Correct 5 ms 2508 KB Output is correct
24 Correct 6 ms 2636 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Runtime error 584 ms 262148 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -