Submission #1069028

# Submission time Handle Problem Language Result Execution time Memory
1069028 2024-08-21T14:41:18 Z _callmelucian Global Warming (CEOI18_glo) C++14
100 / 100
363 ms 22484 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 4e5 + 5;
int a[mn], dp[mn];

vector<pii> cmp;

int getID (int targ, int p) {
    return lower_bound(all(cmp), make_pair(targ, p)) - cmp.begin();
}

struct IT {
    vector<int> tr;
    IT (int sz) : tr(4 * sz) {}

    void update (int pos, int val, int k, int l, int r) {
        if (pos < l || r < pos) return;
        if (l == r) {
            tr[k] = val;
            return;
        }
        int mid = (l + r) >> 1;
        update(pos, val, 2 * k, l, mid);
        update(pos, val, 2 * k + 1, mid + 1, r);
        tr[k] = max(tr[2 * k], tr[2 * k + 1]);
    }

    int query (int a, int b, int k, int l, int r) {
        if (b < l || r < a) return 0;
        if (a <= l && r <= b) return tr[k];
        int mid = (l + r) >> 1;
        return max(query(a, b, 2 * k, l, mid), query(a, b, 2 * k + 1, mid + 1, r));
    }
} preTree(mn), sfxTree(mn);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, x; cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cmp.emplace_back(a[i], i);
        cmp.emplace_back(a[i] - x, i);
    }
    sort(all(cmp)); filter(cmp);

    int mx = cmp.size() - 1, ans = 0;
    for (int i = n; i >= 1; i--) {
        dp[i] = sfxTree.query(getID(a[i], INT_MAX), mx, 1, 0, mx) + 1;
        sfxTree.update(getID(a[i], i), dp[i], 1, 0, mx);
    }

    for (int i = 1; i <= n; i++) {
        sfxTree.update(getID(a[i], i), 0, 1, 0, mx);
        dp[i] = preTree.query(0, getID(a[i] - x, 0) - 1, 1, 0, mx) + 1;
        preTree.update(getID(a[i] - x, i), dp[i], 1, 0, mx);
        ans = max(ans, dp[i] + sfxTree.query(getID(a[i] - x, INT_MAX), mx, 1, 0, mx));
    }
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15056 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 2 ms 14984 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15056 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 2 ms 14984 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14836 KB Output is correct
14 Correct 3 ms 15052 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 2 ms 15056 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15056 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 2 ms 14984 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14836 KB Output is correct
14 Correct 3 ms 15052 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 2 ms 15056 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 15100 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 22484 KB Output is correct
2 Correct 310 ms 20692 KB Output is correct
3 Correct 311 ms 21972 KB Output is correct
4 Correct 350 ms 20944 KB Output is correct
5 Correct 152 ms 21880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 16604 KB Output is correct
2 Correct 92 ms 16856 KB Output is correct
3 Correct 75 ms 16572 KB Output is correct
4 Correct 44 ms 16348 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 44 ms 16392 KB Output is correct
7 Correct 63 ms 16604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 18132 KB Output is correct
2 Correct 152 ms 17880 KB Output is correct
3 Correct 325 ms 20948 KB Output is correct
4 Correct 164 ms 20180 KB Output is correct
5 Correct 86 ms 17624 KB Output is correct
6 Correct 157 ms 20180 KB Output is correct
7 Correct 160 ms 20692 KB Output is correct
8 Correct 123 ms 17876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 15056 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 2 ms 14984 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14836 KB Output is correct
14 Correct 3 ms 15052 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 2 ms 15056 KB Output is correct
17 Correct 3 ms 14936 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 4 ms 14940 KB Output is correct
23 Correct 3 ms 14940 KB Output is correct
24 Correct 3 ms 15100 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 4 ms 14940 KB Output is correct
27 Correct 308 ms 22484 KB Output is correct
28 Correct 310 ms 20692 KB Output is correct
29 Correct 311 ms 21972 KB Output is correct
30 Correct 350 ms 20944 KB Output is correct
31 Correct 152 ms 21880 KB Output is correct
32 Correct 77 ms 16604 KB Output is correct
33 Correct 92 ms 16856 KB Output is correct
34 Correct 75 ms 16572 KB Output is correct
35 Correct 44 ms 16348 KB Output is correct
36 Correct 3 ms 14940 KB Output is correct
37 Correct 44 ms 16392 KB Output is correct
38 Correct 63 ms 16604 KB Output is correct
39 Correct 156 ms 18132 KB Output is correct
40 Correct 152 ms 17880 KB Output is correct
41 Correct 325 ms 20948 KB Output is correct
42 Correct 164 ms 20180 KB Output is correct
43 Correct 86 ms 17624 KB Output is correct
44 Correct 157 ms 20180 KB Output is correct
45 Correct 160 ms 20692 KB Output is correct
46 Correct 123 ms 17876 KB Output is correct
47 Correct 165 ms 17880 KB Output is correct
48 Correct 176 ms 17880 KB Output is correct
49 Correct 363 ms 21304 KB Output is correct
50 Correct 182 ms 21200 KB Output is correct
51 Correct 152 ms 22480 KB Output is correct
52 Correct 200 ms 20948 KB Output is correct
53 Correct 161 ms 20436 KB Output is correct
54 Correct 164 ms 21968 KB Output is correct
55 Correct 268 ms 21716 KB Output is correct