Submission #1098692

# Submission time Handle Problem Language Result Execution time Memory
1098692 2024-10-09T17:52:08 Z ortsac Global Warming (CEOI18_glo) C++17
100 / 100
393 ms 17056 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;

int n, x;

struct SegTree {
    int seg[4*MAXN];

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

    void update(int node, int l, int r, int po, int val) {
        if (l == r) {
            seg[node] = max(seg[node], val);
            return;
        }
        int m = (l+r)/2;
        if (po <= m) update(2*node, l, m, po, val);
        else update(2*node + 1, m + 1, r, po, val);
        seg[node] = max(seg[2*node], seg[2*node + 1]);
    }

    int query(int node, int l, int r, int tl, int tr) {
        if (r < l) return 0;
        if ((r < tl) || (tr < l)) return 0;
        if ((tl <= l) && (r <= tr)) return seg[node];
        int m = (l+r)/2;
        return max(query(2*node, l, m, tl, tr), query(2*node + 1, m + 1, r, tl, tr));
    }
};

int32_t main() {
    cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<int> ord = v;
    sort(ord.begin(), ord.end());
    ord.erase(unique(ord.begin(), ord.end()), ord.end());
    map<int, int> re;
    for (int i = 0; i < ((int)ord.size()); i++) re[ord[i]] = i;
    // calc prefix
    SegTree seg;
    seg.build();
    vector<int> pf(n);
    for (int i = 0; i < n; i++) {
        // calcular pf[i]
        // posso pegar até v[i]+x
        auto it = lower_bound(ord.begin(), ord.end(), v[i] + x);
        int mxPo = (it - ord.begin() - 1);
        //cout << "this is mxpo: " << mxPo << "\n";
        pf[i] = seg.query(1, 0, n - 1, 0, mxPo);
        // atualizar aqui
        int po = re[v[i]];
        int mx = seg.query(1, 0, n - 1, 0, po - 1);
        //cout << mx << "\n";
        seg.update(1, 0, n - 1, po, mx + 1);
    }
    seg.build();
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        // atualizar aqui
        int po = re[v[i]];
        int mx = seg.query(1, 0, n - 1, po + 1, n - 1);
        seg.update(1, 0, n - 1, po, mx + 1);
        ans = max(ans, mx + 1 + pf[i]);
        //cout << i << " " << mx << " " << pf[i] << "\n";
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3564 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3500 KB Output is correct
9 Correct 2 ms 3564 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3564 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3500 KB Output is correct
9 Correct 2 ms 3564 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3416 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3564 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3500 KB Output is correct
9 Correct 2 ms 3564 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3416 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 3 ms 3416 KB Output is correct
20 Correct 3 ms 3476 KB Output is correct
21 Correct 3 ms 3420 KB Output is correct
22 Correct 3 ms 3416 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 3 ms 3420 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 341 ms 16980 KB Output is correct
2 Correct 371 ms 17008 KB Output is correct
3 Correct 365 ms 16988 KB Output is correct
4 Correct 393 ms 16980 KB Output is correct
5 Correct 156 ms 11604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 6964 KB Output is correct
2 Correct 75 ms 6732 KB Output is correct
3 Correct 78 ms 6748 KB Output is correct
4 Correct 33 ms 5468 KB Output is correct
5 Correct 2 ms 3416 KB Output is correct
6 Correct 33 ms 5468 KB Output is correct
7 Correct 58 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 10324 KB Output is correct
2 Correct 143 ms 10320 KB Output is correct
3 Correct 334 ms 16980 KB Output is correct
4 Correct 141 ms 11500 KB Output is correct
5 Correct 84 ms 9808 KB Output is correct
6 Correct 147 ms 15700 KB Output is correct
7 Correct 161 ms 16468 KB Output is correct
8 Correct 118 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3564 KB Output is correct
3 Correct 2 ms 3420 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3500 KB Output is correct
9 Correct 2 ms 3564 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3416 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 3 ms 3416 KB Output is correct
20 Correct 3 ms 3476 KB Output is correct
21 Correct 3 ms 3420 KB Output is correct
22 Correct 3 ms 3416 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 3 ms 3420 KB Output is correct
25 Correct 2 ms 3420 KB Output is correct
26 Correct 2 ms 3420 KB Output is correct
27 Correct 341 ms 16980 KB Output is correct
28 Correct 371 ms 17008 KB Output is correct
29 Correct 365 ms 16988 KB Output is correct
30 Correct 393 ms 16980 KB Output is correct
31 Correct 156 ms 11604 KB Output is correct
32 Correct 70 ms 6964 KB Output is correct
33 Correct 75 ms 6732 KB Output is correct
34 Correct 78 ms 6748 KB Output is correct
35 Correct 33 ms 5468 KB Output is correct
36 Correct 2 ms 3416 KB Output is correct
37 Correct 33 ms 5468 KB Output is correct
38 Correct 58 ms 6736 KB Output is correct
39 Correct 145 ms 10324 KB Output is correct
40 Correct 143 ms 10320 KB Output is correct
41 Correct 334 ms 16980 KB Output is correct
42 Correct 141 ms 11500 KB Output is correct
43 Correct 84 ms 9808 KB Output is correct
44 Correct 147 ms 15700 KB Output is correct
45 Correct 161 ms 16468 KB Output is correct
46 Correct 118 ms 10324 KB Output is correct
47 Correct 158 ms 10192 KB Output is correct
48 Correct 165 ms 10296 KB Output is correct
49 Correct 389 ms 17028 KB Output is correct
50 Correct 147 ms 11632 KB Output is correct
51 Correct 129 ms 10832 KB Output is correct
52 Correct 205 ms 16352 KB Output is correct
53 Correct 159 ms 16380 KB Output is correct
54 Correct 170 ms 17056 KB Output is correct
55 Correct 269 ms 17004 KB Output is correct