Submission #655166

# Submission time Handle Problem Language Result Execution time Memory
655166 2022-11-03T13:03:47 Z ParsaS Global Warming (CEOI18_glo) C++14
100 / 100
69 ms 6144 KB
// In the name of God
#pragma GCC optimize("O2", "unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int N = 2e5 + 5, inf = 2e9 + 5;
int n, x, a[N];
int R[N], L[N];
pair<int, int> p[N];

void solve() {
    cin >> n >> x;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    fill(R, R + N, -inf);
    R[0] = inf;
    for (int i = n - 1; i >= 0; i--) {
        int l = 0, r = N - 1;
        while (r - l > 1) {
            int mid = (l + r) >> 1;
            if (R[mid] > a[i])
                l = mid;
            else
                r = mid;
        }
        p[i] = make_pair(r, R[r]);
        R[r] = a[i];
    }
    int ans = 0;
    fill(L + 1, L + N, inf);
    for (int i = 0; i < n; i++) {
        R[p[i].fi] = p[i].se;

        int j = lower_bound(L, L + N, a[i]) - L;
        L[j] = a[i]; 

        int l = 0, r = N - 1;
        while (r - l > 1) {
            int mid = (l + r) >> 1;
            if (R[mid] + x > a[i])
                l = mid;
            else
                r = mid;
        }
        ans = max(ans, j + l);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1864 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1864 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1864 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 6136 KB Output is correct
2 Correct 68 ms 6144 KB Output is correct
3 Correct 68 ms 6016 KB Output is correct
4 Correct 69 ms 6068 KB Output is correct
5 Correct 60 ms 5380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2900 KB Output is correct
2 Correct 18 ms 2952 KB Output is correct
3 Correct 17 ms 2888 KB Output is correct
4 Correct 16 ms 2768 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 17 ms 2652 KB Output is correct
7 Correct 17 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3916 KB Output is correct
2 Correct 35 ms 4020 KB Output is correct
3 Correct 68 ms 6140 KB Output is correct
4 Correct 59 ms 5324 KB Output is correct
5 Correct 29 ms 3540 KB Output is correct
6 Correct 50 ms 5280 KB Output is correct
7 Correct 56 ms 5956 KB Output is correct
8 Correct 30 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1864 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1868 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
26 Correct 2 ms 1864 KB Output is correct
27 Correct 69 ms 6136 KB Output is correct
28 Correct 68 ms 6144 KB Output is correct
29 Correct 68 ms 6016 KB Output is correct
30 Correct 69 ms 6068 KB Output is correct
31 Correct 60 ms 5380 KB Output is correct
32 Correct 18 ms 2900 KB Output is correct
33 Correct 18 ms 2952 KB Output is correct
34 Correct 17 ms 2888 KB Output is correct
35 Correct 16 ms 2768 KB Output is correct
36 Correct 1 ms 1876 KB Output is correct
37 Correct 17 ms 2652 KB Output is correct
38 Correct 17 ms 2900 KB Output is correct
39 Correct 35 ms 3916 KB Output is correct
40 Correct 35 ms 4020 KB Output is correct
41 Correct 68 ms 6140 KB Output is correct
42 Correct 59 ms 5324 KB Output is correct
43 Correct 29 ms 3540 KB Output is correct
44 Correct 50 ms 5280 KB Output is correct
45 Correct 56 ms 5956 KB Output is correct
46 Correct 30 ms 3916 KB Output is correct
47 Correct 33 ms 3928 KB Output is correct
48 Correct 34 ms 3916 KB Output is correct
49 Correct 65 ms 6072 KB Output is correct
50 Correct 58 ms 5372 KB Output is correct
51 Correct 46 ms 4420 KB Output is correct
52 Correct 58 ms 5444 KB Output is correct
53 Correct 56 ms 5384 KB Output is correct
54 Correct 57 ms 6092 KB Output is correct
55 Correct 59 ms 6080 KB Output is correct