Submission #147631

# Submission time Handle Problem Language Result Execution time Memory
147631 2019-08-30T10:33:00 Z forestryks Global Warming (CEOI18_glo) C++14
100 / 100
396 ms 12780 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
#define rep(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int MAXN = 4e5 + 5;
int n, d;
int a[MAXN];
int b[MAXN];
vector<int> vals;

int t[MAXN * 4];

void build() {
    memset(t, 0, sizeof t);
}

int get(int v, int tl, int tr, int l, int r) {
    if (r <= tl || tr <= l) return 0;
    if (l <= tl && tr <= r) return t[v];

    int tm = tl + (tr - tl) / 2;
    int a = get(v * 2 + 1, tl, tm, l, r);
    int b = get(v * 2 + 2, tm, tr, l, r);
    return max(a, b);
}

void upd(int v, int tl, int tr, int p, int x) {
    if (tr - tl == 1) {
        t[v] = max(t[v], x);
        return;
    }

    int tm = tl + (tr - tl) / 2;
    if (p < tm) {
        upd(v * 2 + 1, tl, tm, p, x);
    } else {
        upd(v * 2 + 2, tm, tr, p, x);
    }
    t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
}

int sz[MAXN];
int res = 1;

int main() {
    FAST_IO;
    cin >> n >> d;
    rep(i, n) {
        cin >> a[i];
    }

    rep(i, n) {
        b[i] = a[i] + d;
    }

    rep(i, n) {
        vals.push_back(a[i]);
        vals.push_back(b[i]);
    }

    sort(all(vals));
    vals.resize(unique(all(vals)) - vals.begin());

    rep(i, n) {
        a[i] = lower_bound(all(vals), a[i]) - vals.begin();
        b[i] = lower_bound(all(vals), b[i]) - vals.begin();
    }

    build();
    rep(i, n) {
        sz[i] = get(0, 0, vals.size(), 0, a[i]) + 1;
        upd(0, 0, vals.size(), a[i], sz[i]);
    }

    build();
    for (int i = n - 1; i >= 0; --i) {
        res = max(res, sz[i] + get(0, 0, vals.size(), a[i] + 1, vals.size()));

        int r = get(0, 0, vals.size(), b[i] + 1, vals.size()) + 1;
        upd(0, 0, vals.size(), b[i], r);
    }

    cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6652 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 7 ms 6648 KB Output is correct
9 Correct 8 ms 6648 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6652 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 7 ms 6648 KB Output is correct
9 Correct 8 ms 6648 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 7 ms 6648 KB Output is correct
13 Correct 8 ms 6648 KB Output is correct
14 Correct 8 ms 6776 KB Output is correct
15 Correct 8 ms 6648 KB Output is correct
16 Correct 8 ms 6648 KB Output is correct
17 Correct 8 ms 6568 KB Output is correct
18 Correct 24 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6652 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 7 ms 6648 KB Output is correct
9 Correct 8 ms 6648 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 7 ms 6648 KB Output is correct
13 Correct 8 ms 6648 KB Output is correct
14 Correct 8 ms 6776 KB Output is correct
15 Correct 8 ms 6648 KB Output is correct
16 Correct 8 ms 6648 KB Output is correct
17 Correct 8 ms 6568 KB Output is correct
18 Correct 24 ms 6648 KB Output is correct
19 Correct 9 ms 6648 KB Output is correct
20 Correct 9 ms 6648 KB Output is correct
21 Correct 11 ms 6648 KB Output is correct
22 Correct 9 ms 6672 KB Output is correct
23 Correct 11 ms 6648 KB Output is correct
24 Correct 10 ms 6648 KB Output is correct
25 Correct 10 ms 6648 KB Output is correct
26 Correct 10 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 367 ms 12584 KB Output is correct
2 Correct 365 ms 12676 KB Output is correct
3 Correct 341 ms 12684 KB Output is correct
4 Correct 361 ms 12648 KB Output is correct
5 Correct 188 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 8208 KB Output is correct
2 Correct 83 ms 8172 KB Output is correct
3 Correct 84 ms 8280 KB Output is correct
4 Correct 50 ms 8052 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 52 ms 8052 KB Output is correct
7 Correct 72 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 9708 KB Output is correct
2 Correct 177 ms 9712 KB Output is correct
3 Correct 396 ms 12780 KB Output is correct
4 Correct 207 ms 11876 KB Output is correct
5 Correct 122 ms 9328 KB Output is correct
6 Correct 220 ms 11832 KB Output is correct
7 Correct 227 ms 12264 KB Output is correct
8 Correct 146 ms 9780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 8 ms 6648 KB Output is correct
4 Correct 8 ms 6648 KB Output is correct
5 Correct 8 ms 6652 KB Output is correct
6 Correct 8 ms 6648 KB Output is correct
7 Correct 8 ms 6648 KB Output is correct
8 Correct 7 ms 6648 KB Output is correct
9 Correct 8 ms 6648 KB Output is correct
10 Correct 8 ms 6648 KB Output is correct
11 Correct 8 ms 6648 KB Output is correct
12 Correct 7 ms 6648 KB Output is correct
13 Correct 8 ms 6648 KB Output is correct
14 Correct 8 ms 6776 KB Output is correct
15 Correct 8 ms 6648 KB Output is correct
16 Correct 8 ms 6648 KB Output is correct
17 Correct 8 ms 6568 KB Output is correct
18 Correct 24 ms 6648 KB Output is correct
19 Correct 9 ms 6648 KB Output is correct
20 Correct 9 ms 6648 KB Output is correct
21 Correct 11 ms 6648 KB Output is correct
22 Correct 9 ms 6672 KB Output is correct
23 Correct 11 ms 6648 KB Output is correct
24 Correct 10 ms 6648 KB Output is correct
25 Correct 10 ms 6648 KB Output is correct
26 Correct 10 ms 6648 KB Output is correct
27 Correct 367 ms 12584 KB Output is correct
28 Correct 365 ms 12676 KB Output is correct
29 Correct 341 ms 12684 KB Output is correct
30 Correct 361 ms 12648 KB Output is correct
31 Correct 188 ms 11756 KB Output is correct
32 Correct 83 ms 8208 KB Output is correct
33 Correct 83 ms 8172 KB Output is correct
34 Correct 84 ms 8280 KB Output is correct
35 Correct 50 ms 8052 KB Output is correct
36 Correct 8 ms 6648 KB Output is correct
37 Correct 52 ms 8052 KB Output is correct
38 Correct 72 ms 8272 KB Output is correct
39 Correct 176 ms 9708 KB Output is correct
40 Correct 177 ms 9712 KB Output is correct
41 Correct 396 ms 12780 KB Output is correct
42 Correct 207 ms 11876 KB Output is correct
43 Correct 122 ms 9328 KB Output is correct
44 Correct 220 ms 11832 KB Output is correct
45 Correct 227 ms 12264 KB Output is correct
46 Correct 146 ms 9780 KB Output is correct
47 Correct 181 ms 9744 KB Output is correct
48 Correct 172 ms 9836 KB Output is correct
49 Correct 380 ms 12524 KB Output is correct
50 Correct 202 ms 12012 KB Output is correct
51 Correct 163 ms 10600 KB Output is correct
52 Correct 230 ms 11920 KB Output is correct
53 Correct 232 ms 12008 KB Output is correct
54 Correct 242 ms 12776 KB Output is correct
55 Correct 310 ms 12568 KB Output is correct