Submission #526813

# Submission time Handle Problem Language Result Execution time Memory
526813 2022-02-16T07:57:22 Z hoanghq2004 Global Warming (CEOI18_glo) C++14
100 / 100
116 ms 7048 KB
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 10;

int n, x;
int a[N], b[N];
int BIT[N], prf[N], suf[N];

void add(int i, int val) {
    for (; i < N; i += i & (- i)) BIT[i] = max(BIT[i], val);
}

int get(int i) {
    int ans = 0;
    for (; i; i -= i & - i) ans = max(ans, BIT[i]);
    return ans;
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> x;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vector <int> dta;
    for (int i = 1; i <= n; ++i) dta.push_back(a[i]);
    sort(dta.begin(), dta.end());
    for (int i = 1; i <= n; ++i) b[i] = lower_bound(dta.begin(), dta.end(), a[i]) - dta.begin() + 1;
    for (int i = 1; i <= n; ++i) {
        prf[i] = get(b[i] - 1) + 1;
        add(b[i], prf[i]);
    }
    memset(BIT, 0, sizeof(BIT));
    for (int i = n; i >= 1; --i) {
        suf[i] = get(n - b[i]) + 1;
        add(n - b[i] + 1, suf[i]);
    }
    memset(BIT, 0, sizeof(BIT));
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int newv = lower_bound(dta.begin(), dta.end(), a[i] + x) - dta.begin() + 1;
        ans = max(ans, get(newv - 1) + suf[i]);
        add(b[i], prf[i]);
    }
    cout << ans;
}

Compilation message

glo.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      | 
glo.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1084 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 1092 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1088 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1084 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 1092 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1088 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1016 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1088 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1084 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 1092 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1088 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1016 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1088 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1088 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 6968 KB Output is correct
2 Correct 116 ms 7048 KB Output is correct
3 Correct 108 ms 7020 KB Output is correct
4 Correct 109 ms 6996 KB Output is correct
5 Correct 55 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2632 KB Output is correct
2 Correct 25 ms 2632 KB Output is correct
3 Correct 26 ms 2584 KB Output is correct
4 Correct 14 ms 2436 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 14 ms 2488 KB Output is correct
7 Correct 20 ms 2700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 4084 KB Output is correct
2 Correct 40 ms 4060 KB Output is correct
3 Correct 95 ms 7020 KB Output is correct
4 Correct 52 ms 6208 KB Output is correct
5 Correct 26 ms 3652 KB Output is correct
6 Correct 55 ms 6092 KB Output is correct
7 Correct 50 ms 6688 KB Output is correct
8 Correct 35 ms 4080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1084 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 1092 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1088 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1100 KB Output is correct
13 Correct 1 ms 1016 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1088 KB Output is correct
18 Correct 1 ms 1104 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 1 ms 1104 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 1 ms 1088 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 107 ms 6968 KB Output is correct
28 Correct 116 ms 7048 KB Output is correct
29 Correct 108 ms 7020 KB Output is correct
30 Correct 109 ms 6996 KB Output is correct
31 Correct 55 ms 6252 KB Output is correct
32 Correct 30 ms 2632 KB Output is correct
33 Correct 25 ms 2632 KB Output is correct
34 Correct 26 ms 2584 KB Output is correct
35 Correct 14 ms 2436 KB Output is correct
36 Correct 1 ms 1100 KB Output is correct
37 Correct 14 ms 2488 KB Output is correct
38 Correct 20 ms 2700 KB Output is correct
39 Correct 41 ms 4084 KB Output is correct
40 Correct 40 ms 4060 KB Output is correct
41 Correct 95 ms 7020 KB Output is correct
42 Correct 52 ms 6208 KB Output is correct
43 Correct 26 ms 3652 KB Output is correct
44 Correct 55 ms 6092 KB Output is correct
45 Correct 50 ms 6688 KB Output is correct
46 Correct 35 ms 4080 KB Output is correct
47 Correct 53 ms 4136 KB Output is correct
48 Correct 57 ms 4164 KB Output is correct
49 Correct 111 ms 6948 KB Output is correct
50 Correct 61 ms 6260 KB Output is correct
51 Correct 49 ms 5104 KB Output is correct
52 Correct 72 ms 6344 KB Output is correct
53 Correct 56 ms 6332 KB Output is correct
54 Correct 51 ms 7040 KB Output is correct
55 Correct 90 ms 6972 KB Output is correct