Submission #486981

# Submission time Handle Problem Language Result Execution time Memory
486981 2021-11-13T17:12:07 Z jalsol Global Warming (CEOI18_glo) C++17
100 / 100
55 ms 3416 KB
#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif

using namespace std;

static const bool __initialization = []() {
    cin.tie(nullptr)->sync_with_stdio(false);
#define TASK "empty"
    if (fopen(TASK".inp", "r")) {
        (void)(!freopen(TASK".inp", "r", stdin));
        (void)(!freopen(TASK".out", "w", stdout)); }
    return true;
}();

using ll = long long;
using ld = long double;
#define fi first
#define se second

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)

template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }

constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxn = 2e5 + 5;

int n, x;
int a[maxn];

int dp[maxn];
vector<int> lis, lds;

signed main() {
    cin >> n >> x;
    For (i, 1, n) cin >> a[i];

    For (i, 1, n) {
        int dist;

        if (isz(lis)) {
            dp[i] = lower_bound(all(lis), a[i] + x) - lis.begin();
            dist = lower_bound(all(lis), a[i]) - lis.begin();
        } else {
            dp[i] = 0;
            dist = 0;
        }
 
        if (dist == isz(lis)) {
            lis.push_back(a[i]);
        } else {
            lis[dist] = a[i];
        }
    }
 
    int ans = 0;

    Ford (i, n, 1) {
        int dist;

        if (isz(lds)) {
            dist = lower_bound(all(lds), -a[i]) - lds.begin();
        } else {
            dist = 0;
        }

        if (dist == isz(lds)) {
            lds.push_back(-a[i]);
        } else {
            lds[dist] = -a[i];
        }
 
        chmax(ans, dp[i] + dist + 1);
    }
 
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2152 KB Output is correct
2 Correct 51 ms 2212 KB Output is correct
3 Correct 52 ms 2252 KB Output is correct
4 Correct 49 ms 2180 KB Output is correct
5 Correct 27 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1100 KB Output is correct
2 Correct 12 ms 1100 KB Output is correct
3 Correct 12 ms 1100 KB Output is correct
4 Correct 7 ms 1296 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 10 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1428 KB Output is correct
2 Correct 21 ms 1500 KB Output is correct
3 Correct 44 ms 2176 KB Output is correct
4 Correct 34 ms 3388 KB Output is correct
5 Correct 13 ms 1992 KB Output is correct
6 Correct 23 ms 3292 KB Output is correct
7 Correct 24 ms 3308 KB Output is correct
8 Correct 18 ms 1496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 324 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 49 ms 2152 KB Output is correct
28 Correct 51 ms 2212 KB Output is correct
29 Correct 52 ms 2252 KB Output is correct
30 Correct 49 ms 2180 KB Output is correct
31 Correct 27 ms 3320 KB Output is correct
32 Correct 12 ms 1100 KB Output is correct
33 Correct 12 ms 1100 KB Output is correct
34 Correct 12 ms 1100 KB Output is correct
35 Correct 7 ms 1296 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 7 ms 1220 KB Output is correct
38 Correct 10 ms 1100 KB Output is correct
39 Correct 21 ms 1428 KB Output is correct
40 Correct 21 ms 1500 KB Output is correct
41 Correct 44 ms 2176 KB Output is correct
42 Correct 34 ms 3388 KB Output is correct
43 Correct 13 ms 1992 KB Output is correct
44 Correct 23 ms 3292 KB Output is correct
45 Correct 24 ms 3308 KB Output is correct
46 Correct 18 ms 1496 KB Output is correct
47 Correct 24 ms 1484 KB Output is correct
48 Correct 25 ms 1456 KB Output is correct
49 Correct 55 ms 2216 KB Output is correct
50 Correct 39 ms 3416 KB Output is correct
51 Correct 22 ms 3012 KB Output is correct
52 Correct 29 ms 3388 KB Output is correct
53 Correct 24 ms 3304 KB Output is correct
54 Correct 25 ms 3400 KB Output is correct
55 Correct 39 ms 2192 KB Output is correct