Submission #482620

# Submission time Handle Problem Language Result Execution time Memory
482620 2021-10-25T22:37:55 Z Ozy Global Warming (CEOI18_glo) C++17
38 / 100
113 ms 9636 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 200000
#define LIM 2000000001
#define alt first
#define val second

lli n,x,res,a,num;
lli arr[MAX+2] , elevados[MAX+2];
set<pair<lli,lli> > lis;
set<pair<lli,lli> >::iterator it,pas;
bool gf;

void LIS(lli act,lli pos) {

    pair<lli,lli> nuevo;

    if (lis.empty()) lis.insert({act,1ll});
    else {

        it = lis.lower_bound({act,0});
        if (it == lis.begin()) nuevo = {act,1};
        else {
            it--;
            nuevo = {act, (*it).val + 1};
        }

        it++;
        while (true) {

            if (it == lis.end()) break;
            if ( (*it).val > nuevo.val) break;

            pas = it;
            it++;
            lis.erase(pas);

        }
        lis.insert({nuevo});
    }

}


void LISa(lli act,lli pos) {

    pair<lli,lli> nuevo;

    if (lis.empty()) {
        lis.insert({act,1});
        elevados[pos] = 1;
    }
    else {

        it = lis.upper_bound({act,LIM+2});
        if (it == lis.end()) nuevo = {act,1};
        else nuevo = {act, (*it).val + 1};

        gf = false;
        do {
            if (it == lis.begin()) break;
            else {
                it--;
                if (gf) lis.erase(pas);
                gf =true;
                pas=it;
            }

            if ( (*it).val > nuevo.val) break;

        } while (true);

        lis.insert(nuevo);
        elevados[pos] = nuevo.val;
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //leer
    cin >> n >> x;
    rep(i,1,n) cin >> arr[i];

    // LIS al reves y asignar valores a cada i
    repa(i,n,1) LISa(arr[i],i);

    // lis hacia enfrente, checar primero y luego agregar al LIS
    lis.clear();
    rep(i,1,n) {

        num = arr[i] + x;

        if (i > 1) {

            it = lis.upper_bound({num-1,LIM+2});
            if (it != lis.begin()) {
                it--;
                a = (*it).val;
            }
            else a = 0;

        }
        else a = 0;

        a += elevados[i];
        if (a > res) res = a;


        LIS(arr[i],i);

    }

    //Imprimir
    cout << res;
}
# 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 332 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 332 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 332 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 332 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 0 ms 204 KB Output is correct
16 Correct 0 ms 252 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 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 332 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 332 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 0 ms 204 KB Output is correct
16 Correct 0 ms 252 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 3476 KB Output is correct
2 Correct 105 ms 3444 KB Output is correct
3 Correct 106 ms 3396 KB Output is correct
4 Correct 113 ms 3500 KB Output is correct
5 Correct 102 ms 9636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1100 KB Output is correct
2 Correct 25 ms 1092 KB Output is correct
3 Correct 27 ms 1100 KB Output is correct
4 Correct 23 ms 2556 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 23 ms 2600 KB Output is correct
7 Incorrect 20 ms 1100 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1816 KB Output is correct
2 Correct 46 ms 1868 KB Output is correct
3 Correct 97 ms 3424 KB Output is correct
4 Correct 105 ms 9632 KB Output is correct
5 Correct 48 ms 4932 KB Output is correct
6 Correct 99 ms 9152 KB Output is correct
7 Correct 90 ms 9224 KB Output is correct
8 Incorrect 43 ms 1892 KB Output isn't 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 332 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 332 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 0 ms 204 KB Output is correct
16 Correct 0 ms 252 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 106 ms 3476 KB Output is correct
28 Correct 105 ms 3444 KB Output is correct
29 Correct 106 ms 3396 KB Output is correct
30 Correct 113 ms 3500 KB Output is correct
31 Correct 102 ms 9636 KB Output is correct
32 Correct 25 ms 1100 KB Output is correct
33 Correct 25 ms 1092 KB Output is correct
34 Correct 27 ms 1100 KB Output is correct
35 Correct 23 ms 2556 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 23 ms 2600 KB Output is correct
38 Incorrect 20 ms 1100 KB Output isn't correct