Submission #162076

# Submission time Handle Problem Language Result Execution time Memory
162076 2019-11-06T09:05:27 Z Akashi Global Warming (CEOI18_glo) C++14
100 / 100
709 ms 158968 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]);
    }

    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]);
                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory 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 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1176 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 1144 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory 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 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1176 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 1144 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 1144 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
# Verdict Execution time Memory 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 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1176 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 1144 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 1144 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 6 ms 2424 KB Output is correct
20 Correct 6 ms 2424 KB Output is correct
21 Correct 6 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 4 ms 1784 KB Output is correct
25 Correct 3 ms 1144 KB Output is correct
26 Correct 4 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 3464 KB Output is correct
2 Correct 69 ms 3516 KB Output is correct
3 Correct 69 ms 3420 KB Output is correct
4 Correct 71 ms 3412 KB Output is correct
5 Correct 40 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 46716 KB Output is correct
2 Correct 149 ms 46712 KB Output is correct
3 Correct 146 ms 46768 KB Output is correct
4 Correct 76 ms 25720 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 47 ms 4856 KB Output is correct
7 Correct 107 ms 32888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 86392 KB Output is correct
2 Correct 272 ms 86204 KB Output is correct
3 Correct 535 ms 158968 KB Output is correct
4 Correct 244 ms 87416 KB Output is correct
5 Correct 62 ms 8568 KB Output is correct
6 Correct 118 ms 15196 KB Output is correct
7 Correct 122 ms 15228 KB Output is correct
8 Correct 194 ms 60536 KB Output is correct
# Verdict Execution time Memory 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 1144 KB Output is correct
6 Correct 3 ms 1144 KB Output is correct
7 Correct 3 ms 1176 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 1144 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 1144 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 6 ms 2424 KB Output is correct
20 Correct 6 ms 2424 KB Output is correct
21 Correct 6 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 4 ms 1784 KB Output is correct
25 Correct 3 ms 1144 KB Output is correct
26 Correct 4 ms 1272 KB Output is correct
27 Correct 69 ms 3464 KB Output is correct
28 Correct 69 ms 3516 KB Output is correct
29 Correct 69 ms 3420 KB Output is correct
30 Correct 71 ms 3412 KB Output is correct
31 Correct 40 ms 3448 KB Output is correct
32 Correct 148 ms 46716 KB Output is correct
33 Correct 149 ms 46712 KB Output is correct
34 Correct 146 ms 46768 KB Output is correct
35 Correct 76 ms 25720 KB Output is correct
36 Correct 3 ms 1144 KB Output is correct
37 Correct 47 ms 4856 KB Output is correct
38 Correct 107 ms 32888 KB Output is correct
39 Correct 286 ms 86392 KB Output is correct
40 Correct 272 ms 86204 KB Output is correct
41 Correct 535 ms 158968 KB Output is correct
42 Correct 244 ms 87416 KB Output is correct
43 Correct 62 ms 8568 KB Output is correct
44 Correct 118 ms 15196 KB Output is correct
45 Correct 122 ms 15228 KB Output is correct
46 Correct 194 ms 60536 KB Output is correct
47 Correct 298 ms 86176 KB Output is correct
48 Correct 305 ms 86264 KB Output is correct
49 Correct 709 ms 158864 KB Output is correct
50 Correct 277 ms 87440 KB Output is correct
51 Correct 119 ms 9168 KB Output is correct
52 Correct 204 ms 16120 KB Output is correct
53 Correct 116 ms 15992 KB Output is correct
54 Correct 121 ms 15992 KB Output is correct
55 Correct 446 ms 111428 KB Output is correct