Submission #493773

# Submission time Handle Problem Language Result Execution time Memory
493773 2021-12-13T00:22:45 Z Deepesson Global Warming (CEOI18_glo) C++17
75 / 100
924 ms 262144 KB
#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){
    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){
        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 = 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:40:9: warning: unused variable 'a' [-Wunused-variable]
   40 |     int a = update(t,k,&mem[v->left]);
      |         ^
glo.cpp:41:9: warning: unused variable 'b' [-Wunused-variable]
   41 |     int b = update(t,k,&mem[v->right]);
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 0 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 1 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 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 4 ms 2508 KB Output is correct
20 Correct 4 ms 2380 KB Output is correct
21 Correct 4 ms 2252 KB Output is correct
22 Correct 4 ms 1868 KB Output is correct
23 Correct 3 ms 1228 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 727 ms 195412 KB Output is correct
2 Correct 731 ms 195368 KB Output is correct
3 Correct 701 ms 195228 KB Output is correct
4 Correct 699 ms 195296 KB Output is correct
5 Correct 417 ms 106116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 61196 KB Output is correct
2 Correct 176 ms 61292 KB Output is correct
3 Correct 170 ms 61260 KB Output is correct
4 Correct 111 ms 32936 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 88 ms 4464 KB Output is correct
7 Correct 142 ms 42384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 105648 KB Output is correct
2 Correct 312 ms 105600 KB Output is correct
3 Correct 658 ms 195356 KB Output is correct
4 Correct 395 ms 106112 KB Output is correct
5 Correct 153 ms 8964 KB Output is correct
6 Correct 291 ms 16364 KB Output is correct
7 Correct 308 ms 15988 KB Output is correct
8 Correct 251 ms 73236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 4 ms 2508 KB Output is correct
20 Correct 4 ms 2380 KB Output is correct
21 Correct 4 ms 2252 KB Output is correct
22 Correct 4 ms 1868 KB Output is correct
23 Correct 3 ms 1228 KB Output is correct
24 Correct 3 ms 1228 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 727 ms 195412 KB Output is correct
28 Correct 731 ms 195368 KB Output is correct
29 Correct 701 ms 195228 KB Output is correct
30 Correct 699 ms 195296 KB Output is correct
31 Correct 417 ms 106116 KB Output is correct
32 Correct 166 ms 61196 KB Output is correct
33 Correct 176 ms 61292 KB Output is correct
34 Correct 170 ms 61260 KB Output is correct
35 Correct 111 ms 32936 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 88 ms 4464 KB Output is correct
38 Correct 142 ms 42384 KB Output is correct
39 Correct 307 ms 105648 KB Output is correct
40 Correct 312 ms 105600 KB Output is correct
41 Correct 658 ms 195356 KB Output is correct
42 Correct 395 ms 106112 KB Output is correct
43 Correct 153 ms 8964 KB Output is correct
44 Correct 291 ms 16364 KB Output is correct
45 Correct 308 ms 15988 KB Output is correct
46 Correct 251 ms 73236 KB Output is correct
47 Correct 362 ms 131224 KB Output is correct
48 Correct 364 ms 141892 KB Output is correct
49 Runtime error 924 ms 262144 KB Execution killed with signal 6
50 Halted 0 ms 0 KB -