답안 #162075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162075 2019-11-06T09:02:27 Z Akashi Global Warming (CEOI18_glo) C++14
100 / 100
1373 ms 160988 KB
#include <bits/stdc++.h>
using namespace std;

int n, x;
int a[200005], s[200005];
int suf[200005], pref[200005];

int Sol = 0;

void find_lis(int d[], int st, int dr, int sgn){
    int L = 0;
    memset(s, 0, sizeof(s));

    for(int i = st; i != dr ; i += sgn){
        a[i] = a[i] * sgn;

        if(s[L] < a[i] || L == 0){
            s[++L] = a[i];
            d[i] = L;
        }
        else{
            int l = 1, dr = L;
            bool ok = true;
            while(l <= dr){
                int mij = (l + dr) / 2;

                if(s[mij] == a[i]){
                    ok = false;
                    d[i] = mij;
                    break ;
                }

                if(s[mij] > a[i]) dr = mij - 1;
                else l = mij + 1;
            }

            if(s[dr] == a[i]){
                ok = false;
                d[i] = dr;
            }

            if(!ok) continue ;

            s[l] = a[i], d[i] = l;
        }
    }

    Sol = max(Sol, L);

    for(int i = 1; i <= n ; ++i) a[i] = a[i] * sgn;
}

struct node{
    int val;
    node *left, *right;

    node(){
        val = 0;
        left = right = 0;
    }
};

node *arb;

int query(int x, int y, int st = 1, int dr = 1e9, node *nod = arb){
    if(nod == NULL) return 0;
    if(x <= st && dr <= y) return nod->val;

    int mij = (st + dr) / 2;
    int a1 = 0, a2 = 0;
    if(x <= mij) a1 = query(x, y, st, mij, nod->left);
    if(mij + 1 <= y) a2 = query(x, y, mij + 1, dr, nod->right);

    return max(a1, a2);
}

void update(int val, int pos, int st = 1, int dr = 1e9, node *nod = arb){
    if(st == dr){
        nod->val = val;
        return ;
    }

    if(nod->left == NULL) nod->left = new node;
    if(nod->right == NULL) nod->right = new node;

    int mij = (st + dr) / 2;
    if(pos <= mij){
        update(val, pos, st, mij, nod->left);
    }
    else{
        update(val, pos, mij + 1, dr, nod->right);
    }

    nod->val = max(nod->left->val, nod->right->val);
}

void build(int st = 1, int dr = 1e9, node *nod = arb){
    if(nod == NULL) return ;
    if(st == dr){
        nod->val = 0;
        return ;
    }

    int mij = (st + dr) / 2;
    build(st, mij, nod->left);
    build(mij + 1, dr, nod->right);

    nod->val = 0;
}

int main()
{
//    freopen("1.in", "r", stdin);

    scanf("%d%d", &n, &x);

    for(int i = 1; i <= n ; ++i) scanf("%d", &a[i]);

    find_lis(pref, 1, n + 1, 1);
    find_lis(suf, n, 0, -1);

    if(x == 0){
        printf("%d", Sol);
        return 0;
    }

    arb = new node;
    update(pref[1], a[1]);
    for(int i = 1; i < n ; ++i){
        int aux = suf[i + 1];
        aux = aux + query(max(a[i + 1] - x + 1, 1), min(a[i + 1] + x - 1, 1000000000));
        Sol = max(Sol, aux);

        update(pref[i + 1], a[i + 1]);
    }

    build();
    update(suf[n], a[n]);
    for(int i = n; i > 1 ; --i){
        int aux = pref[i - 1];
        aux = aux + query(max(a[i - 1] - x + 1, 1), min(a[i - 1] + x - 1, 1000000000));
        Sol = max(Sol, aux);

        update(suf[i - 1], a[i - 1]);
    }

    printf("%d", Sol);

    return 0;
}

















Compilation message

glo.cpp: In function 'int main()':
glo.cpp:115:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &x);
     ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:117:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n ; ++i) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1136 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1136 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 9 ms 2424 KB Output is correct
20 Correct 7 ms 2456 KB Output is correct
21 Correct 7 ms 2424 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 5 ms 1784 KB Output is correct
24 Correct 5 ms 1784 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 4 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 3576 KB Output is correct
2 Correct 72 ms 3512 KB Output is correct
3 Correct 71 ms 3704 KB Output is correct
4 Correct 139 ms 3580 KB Output is correct
5 Correct 39 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 46768 KB Output is correct
2 Correct 278 ms 46880 KB Output is correct
3 Correct 272 ms 46876 KB Output is correct
4 Correct 122 ms 25848 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 78 ms 4984 KB Output is correct
7 Correct 191 ms 33016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 86392 KB Output is correct
2 Correct 542 ms 86392 KB Output is correct
3 Correct 954 ms 160988 KB Output is correct
4 Correct 353 ms 88572 KB Output is correct
5 Correct 96 ms 9080 KB Output is correct
6 Correct 175 ms 16508 KB Output is correct
7 Correct 185 ms 17144 KB Output is correct
8 Correct 324 ms 61372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1148 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 3 ms 1144 KB Output is correct
10 Correct 3 ms 1148 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1144 KB Output is correct
13 Correct 3 ms 1136 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 9 ms 2424 KB Output is correct
20 Correct 7 ms 2456 KB Output is correct
21 Correct 7 ms 2424 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 5 ms 1784 KB Output is correct
24 Correct 5 ms 1784 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 4 ms 1148 KB Output is correct
27 Correct 71 ms 3576 KB Output is correct
28 Correct 72 ms 3512 KB Output is correct
29 Correct 71 ms 3704 KB Output is correct
30 Correct 139 ms 3580 KB Output is correct
31 Correct 39 ms 3576 KB Output is correct
32 Correct 305 ms 46768 KB Output is correct
33 Correct 278 ms 46880 KB Output is correct
34 Correct 272 ms 46876 KB Output is correct
35 Correct 122 ms 25848 KB Output is correct
36 Correct 3 ms 1144 KB Output is correct
37 Correct 78 ms 4984 KB Output is correct
38 Correct 191 ms 33016 KB Output is correct
39 Correct 455 ms 86392 KB Output is correct
40 Correct 542 ms 86392 KB Output is correct
41 Correct 954 ms 160988 KB Output is correct
42 Correct 353 ms 88572 KB Output is correct
43 Correct 96 ms 9080 KB Output is correct
44 Correct 175 ms 16508 KB Output is correct
45 Correct 185 ms 17144 KB Output is correct
46 Correct 324 ms 61372 KB Output is correct
47 Correct 553 ms 87344 KB Output is correct
48 Correct 563 ms 87288 KB Output is correct
49 Correct 1373 ms 160912 KB Output is correct
50 Correct 427 ms 88648 KB Output is correct
51 Correct 210 ms 9976 KB Output is correct
52 Correct 348 ms 17448 KB Output is correct
53 Correct 180 ms 17320 KB Output is correct
54 Correct 186 ms 17912 KB Output is correct
55 Correct 806 ms 113284 KB Output is correct