답안 #901955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901955 2024-01-10T04:48:44 Z Ghetto Global Warming (CEOI18_glo) C++17
100 / 100
549 ms 106924 KB
#include <bits/stdc++.h>   
using namespace std;
const int MAX_N = 2e5 + 5, MAX_LOG_ARR = 30 + 2, MAX_ARR = 1e9;

int n, x;
int arr[MAX_N];

int l_dp[MAX_N], r_dp[MAX_N];

int segtree[4 * MAX_N * MAX_LOG_ARR]; // Test
int n_nodes;
int l_child[4 * MAX_N * MAX_LOG_ARR], r_child[4 * MAX_N * MAX_LOG_ARR];
void init() {
    for (int i = 1; i <= n_nodes; i++) {
        segtree[i] = 0;
        l_child[i] = r_child[i] = 0;
    }
    n_nodes = 1;
}
void propogate(int u) {
    if (l_child[u]) return;

    n_nodes++;
    l_child[u] = n_nodes;
    n_nodes++;
    r_child[u] = n_nodes;
}
void update(int i, int val, int u = 1, int lo = 0, int hi = MAX_ARR) {
    if (lo == hi) {
        segtree[u] = val;
        return;
    }

    propogate(u);
    int mid = (lo + hi) / 2;
    if (i <= mid) update(i, val, l_child[u], lo, mid);
    else update(i, val, r_child[u], mid + 1, hi);
    segtree[u] = max(segtree[l_child[u]], segtree[r_child[u]]);
}
int query(int l, int r, int u = 1, int lo = 0, int hi = MAX_ARR) {
    if (l <= lo && hi <= r) 
        return segtree[u];

    propogate(u);
    int mid = (lo + hi) / 2, ans = 0;
    if (l <= mid) ans = max(ans, query(l, r, l_child[u], lo, mid));
    if (r > mid) ans = max(ans, query(l, r, r_child[u], mid + 1, hi));
    return ans;
}

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

    cin >> n >> x;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];

    init();
    for (int i = 1; i <= n; i++) {
        l_dp[i] = query(0, arr[i] - 1) + 1;
        update(arr[i], l_dp[i]);
    }

    init();
    for (int i = n; i >= 1; i--) {
        r_dp[i] = query(max(arr[i] - x + 1, 1), MAX_ARR);
        update(arr[i], query(arr[i] + 1, MAX_ARR) + 1);
    }

    // for (int i = 1; i <= n; i++) {
    //     cout << i << ": " << l_dp[i] << " " << r_dp[i] << endl;
    // }

    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(ans, l_dp[i] + r_dp[i]);
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 3 ms 5212 KB Output is correct
21 Correct 4 ms 5208 KB Output is correct
22 Correct 2 ms 2904 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 63140 KB Output is correct
2 Correct 492 ms 65360 KB Output is correct
3 Correct 464 ms 63152 KB Output is correct
4 Correct 476 ms 63316 KB Output is correct
5 Correct 239 ms 37084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 24132 KB Output is correct
2 Correct 96 ms 23892 KB Output is correct
3 Correct 102 ms 23948 KB Output is correct
4 Correct 70 ms 13648 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 55 ms 5700 KB Output is correct
7 Correct 77 ms 18260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 36180 KB Output is correct
2 Correct 207 ms 36176 KB Output is correct
3 Correct 456 ms 63092 KB Output is correct
4 Correct 236 ms 37084 KB Output is correct
5 Correct 108 ms 6484 KB Output is correct
6 Correct 207 ms 8532 KB Output is correct
7 Correct 215 ms 10188 KB Output is correct
8 Correct 165 ms 25936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2548 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
20 Correct 3 ms 5212 KB Output is correct
21 Correct 4 ms 5208 KB Output is correct
22 Correct 2 ms 2904 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 452 ms 63140 KB Output is correct
28 Correct 492 ms 65360 KB Output is correct
29 Correct 464 ms 63152 KB Output is correct
30 Correct 476 ms 63316 KB Output is correct
31 Correct 239 ms 37084 KB Output is correct
32 Correct 105 ms 24132 KB Output is correct
33 Correct 96 ms 23892 KB Output is correct
34 Correct 102 ms 23948 KB Output is correct
35 Correct 70 ms 13648 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 55 ms 5700 KB Output is correct
38 Correct 77 ms 18260 KB Output is correct
39 Correct 199 ms 36180 KB Output is correct
40 Correct 207 ms 36176 KB Output is correct
41 Correct 456 ms 63092 KB Output is correct
42 Correct 236 ms 37084 KB Output is correct
43 Correct 108 ms 6484 KB Output is correct
44 Correct 207 ms 8532 KB Output is correct
45 Correct 215 ms 10188 KB Output is correct
46 Correct 165 ms 25936 KB Output is correct
47 Correct 210 ms 50512 KB Output is correct
48 Correct 216 ms 57092 KB Output is correct
49 Correct 549 ms 106924 KB Output is correct
50 Correct 246 ms 58844 KB Output is correct
51 Correct 164 ms 7976 KB Output is correct
52 Correct 213 ms 10248 KB Output is correct
53 Correct 215 ms 10064 KB Output is correct
54 Correct 239 ms 12292 KB Output is correct
55 Correct 391 ms 73236 KB Output is correct