Submission #217873

# Submission time Handle Problem Language Result Execution time Memory
217873 2020-03-31T06:10:08 Z PeppaPig Global Warming (CEOI18_glo) C++14
100 / 100
182 ms 7268 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int t[N << 1];

void update(int x, int k) {
    for(t[x += N] = k; x != 1; x >>= 1)
        t[x >> 1] = max(t[x], t[x ^ 1]);
}

int query(int l, int r) {
    int ret = 0;
    for(l += N, r += N + 1; l < r; l >>= 1, r >>= 1) {
        if(l & 1) ret = max(ret, t[l++]);
        if(r & 1) ret = max(ret, t[--r]);
    }
    return ret;
}

int n, x;
int A[N], pos[N];
vector<int> coord;

int main() {
    scanf("%d %d", &n, &x);
    vector<int> V;
    for(int i = 1; i <= n; i++) {
        scanf("%d", A + i);
        coord.emplace_back(A[i]), V.emplace_back(i);
    }
    sort(coord.begin(), coord.end());
    sort(V.begin(), V.end(), [&](int a, int b) { return A[a] < A[b]; });
    for(int i = 0; i < n; i++) pos[V[i]] = i + 1;

    V.clear();
    for(int i = 1, z; i <= n; i++) {
        if(V.empty() || V.back() < A[i]) V.emplace_back(A[i]), z = V.size();
        else {
            auto it = lower_bound(V.begin(), V.end(), A[i]);
            *it = A[i], z = it - V.begin() + 1;
        }
        update(pos[i], z); 
    }
    int ans = V.size();
    V.clear();
    for(int i = n, z; i; i--) {
        update(pos[i], 0);
        if(V.empty() || V.back() > A[i]) V.emplace_back(A[i]), z = V.size();
        else {
            auto it = lower_bound(V.begin(), V.end(), A[i], greater<int>());
            *it = A[i], z = it - V.begin() + 1;
        }
        int idx = lower_bound(coord.begin(), coord.end(), A[i] + x) - coord.begin();
        ans = max(ans, z + query(1, idx));
    }
    printf("%d\n", ans);

    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &x);
     ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", A + i);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 7136 KB Output is correct
2 Correct 182 ms 7148 KB Output is correct
3 Correct 175 ms 7140 KB Output is correct
4 Correct 177 ms 7268 KB Output is correct
5 Correct 86 ms 6372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2172 KB Output is correct
2 Correct 45 ms 2172 KB Output is correct
3 Correct 43 ms 2300 KB Output is correct
4 Correct 28 ms 2052 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 24 ms 2044 KB Output is correct
7 Correct 36 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 3820 KB Output is correct
2 Correct 67 ms 3820 KB Output is correct
3 Correct 136 ms 7136 KB Output is correct
4 Correct 87 ms 6368 KB Output is correct
5 Correct 40 ms 3436 KB Output is correct
6 Correct 62 ms 6244 KB Output is correct
7 Correct 68 ms 6884 KB Output is correct
8 Correct 57 ms 3892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 182 ms 7136 KB Output is correct
28 Correct 182 ms 7148 KB Output is correct
29 Correct 175 ms 7140 KB Output is correct
30 Correct 177 ms 7268 KB Output is correct
31 Correct 86 ms 6372 KB Output is correct
32 Correct 43 ms 2172 KB Output is correct
33 Correct 45 ms 2172 KB Output is correct
34 Correct 43 ms 2300 KB Output is correct
35 Correct 28 ms 2052 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 24 ms 2044 KB Output is correct
38 Correct 36 ms 2300 KB Output is correct
39 Correct 67 ms 3820 KB Output is correct
40 Correct 67 ms 3820 KB Output is correct
41 Correct 136 ms 7136 KB Output is correct
42 Correct 87 ms 6368 KB Output is correct
43 Correct 40 ms 3436 KB Output is correct
44 Correct 62 ms 6244 KB Output is correct
45 Correct 68 ms 6884 KB Output is correct
46 Correct 57 ms 3892 KB Output is correct
47 Correct 89 ms 3820 KB Output is correct
48 Correct 92 ms 3944 KB Output is correct
49 Correct 177 ms 7136 KB Output is correct
50 Correct 92 ms 6372 KB Output is correct
51 Correct 87 ms 5116 KB Output is correct
52 Correct 96 ms 6496 KB Output is correct
53 Correct 65 ms 6500 KB Output is correct
54 Correct 70 ms 7140 KB Output is correct
55 Correct 145 ms 7140 KB Output is correct