답안 #482623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482623 2021-10-25T22:54:27 Z Ozy Global Warming (CEOI18_glo) C++17
100 / 100
114 ms 9796 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 2000000000
#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};

        if (it != lis.begin()){
            it--;
            lis.erase(it);
        }

        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;
}
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 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
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 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 0 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
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 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 0 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 3500 KB Output is correct
2 Correct 101 ms 3476 KB Output is correct
3 Correct 102 ms 3480 KB Output is correct
4 Correct 102 ms 3396 KB Output is correct
5 Correct 97 ms 9660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1172 KB Output is correct
2 Correct 25 ms 1136 KB Output is correct
3 Correct 24 ms 1100 KB Output is correct
4 Correct 21 ms 2604 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 21 ms 2676 KB Output is correct
7 Correct 19 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1836 KB Output is correct
2 Correct 45 ms 1868 KB Output is correct
3 Correct 94 ms 3444 KB Output is correct
4 Correct 108 ms 9652 KB Output is correct
5 Correct 47 ms 4996 KB Output is correct
6 Correct 98 ms 9204 KB Output is correct
7 Correct 91 ms 9188 KB Output is correct
8 Correct 36 ms 1788 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 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 0 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 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 104 ms 3500 KB Output is correct
28 Correct 101 ms 3476 KB Output is correct
29 Correct 102 ms 3480 KB Output is correct
30 Correct 102 ms 3396 KB Output is correct
31 Correct 97 ms 9660 KB Output is correct
32 Correct 24 ms 1172 KB Output is correct
33 Correct 25 ms 1136 KB Output is correct
34 Correct 24 ms 1100 KB Output is correct
35 Correct 21 ms 2604 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 21 ms 2676 KB Output is correct
38 Correct 19 ms 1100 KB Output is correct
39 Correct 45 ms 1836 KB Output is correct
40 Correct 45 ms 1868 KB Output is correct
41 Correct 94 ms 3444 KB Output is correct
42 Correct 108 ms 9652 KB Output is correct
43 Correct 47 ms 4996 KB Output is correct
44 Correct 98 ms 9204 KB Output is correct
45 Correct 91 ms 9188 KB Output is correct
46 Correct 36 ms 1788 KB Output is correct
47 Correct 51 ms 2056 KB Output is correct
48 Correct 51 ms 1956 KB Output is correct
49 Correct 106 ms 3556 KB Output is correct
50 Correct 100 ms 9724 KB Output is correct
51 Correct 102 ms 9008 KB Output is correct
52 Correct 100 ms 9732 KB Output is correct
53 Correct 114 ms 9780 KB Output is correct
54 Correct 96 ms 9796 KB Output is correct
55 Correct 82 ms 3552 KB Output is correct