답안 #581387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581387 2022-06-22T14:56:21 Z drdilyor Global Warming (CEOI18_glo) C++17
100 / 100
86 ms 7764 KB
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS)
    #define _GLIBCXX_ASSERTIONS
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K>
using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T>
using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings

const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1e5;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

struct Fenwick {
    int n;
    vi tree;
    Fenwick(int n) : n(n), tree(n) {}
    void set_(int i, int d) {
        for (; i < n; i |= i + 1) tree[i] = max(tree[i], d);
    }
    int max_(int i) {
        i = min(i, n-1);
        int res = 0;
        for (; i >= 0; i = (i & (i+1))-1) res = max(res, tree[i]);
        return res;
    }
};

int solve() {
    int n, x; cin >> n >> x;
    vi a(n); for (auto& i : a) cin >> i;

    // compress
    vi highest(n), b(n);
    {
        vi ix(n);
        for (int i = 0; i < n; i++) ix[i] = i;
        sort(allit(ix), [&](int i, int j) { return a[i] < a[j]; });
        for (int i = 0, prev = -1, key = -1; i < n; i++) {
            if (a[ix[i]] == prev) b[ix[i]] = key;
            else {
                prev = a[ix[i]];
                b[ix[i]] = ++key;
            }
        }

        for (int i = 0; i < n; i++) {
            int l = -1, r = n;
            while (l < r - 1) {
                int mid = (l + r) / 2;
                if (a[ix[mid]] < a[ix[i]] + x) l = mid;
                else r = mid;
            }
            highest[ix[i]] = l >= 0 ? b[ix[l]] : -1;
        }
    }

    vector<vi> dp(2, vi(n));
    Fenwick tree1(n), tree2(n);

    int res = 0;
    for (int i = 0; i < n; i++) {
        dp[0][i] = tree1.max_(b[i]-1) + 1;
        dp[1][i] = max(tree1.max_(highest[i]), tree2.max_(b[i]-1)) + 1;
        tree1.set_(b[i], dp[0][i]);
        tree2.set_(b[i], dp[1][i]);
        res = max({res, dp[1][i]});
    }
    cout << res;
    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 5700 KB Output is correct
2 Correct 74 ms 5740 KB Output is correct
3 Correct 72 ms 5736 KB Output is correct
4 Correct 73 ms 5752 KB Output is correct
5 Correct 53 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1624 KB Output is correct
2 Correct 18 ms 1680 KB Output is correct
3 Correct 17 ms 1680 KB Output is correct
4 Correct 12 ms 1648 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 1680 KB Output is correct
7 Correct 19 ms 1680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3028 KB Output is correct
2 Correct 32 ms 3016 KB Output is correct
3 Correct 70 ms 5808 KB Output is correct
4 Correct 48 ms 5692 KB Output is correct
5 Correct 21 ms 3020 KB Output is correct
6 Correct 39 ms 5520 KB Output is correct
7 Correct 43 ms 5452 KB Output is correct
8 Correct 29 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 86 ms 5700 KB Output is correct
28 Correct 74 ms 5740 KB Output is correct
29 Correct 72 ms 5736 KB Output is correct
30 Correct 73 ms 5752 KB Output is correct
31 Correct 53 ms 5752 KB Output is correct
32 Correct 18 ms 1624 KB Output is correct
33 Correct 18 ms 1680 KB Output is correct
34 Correct 17 ms 1680 KB Output is correct
35 Correct 12 ms 1648 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 12 ms 1680 KB Output is correct
38 Correct 19 ms 1680 KB Output is correct
39 Correct 31 ms 3028 KB Output is correct
40 Correct 32 ms 3016 KB Output is correct
41 Correct 70 ms 5808 KB Output is correct
42 Correct 48 ms 5692 KB Output is correct
43 Correct 21 ms 3020 KB Output is correct
44 Correct 39 ms 5520 KB Output is correct
45 Correct 43 ms 5452 KB Output is correct
46 Correct 29 ms 3020 KB Output is correct
47 Correct 37 ms 3900 KB Output is correct
48 Correct 39 ms 4024 KB Output is correct
49 Correct 75 ms 7736 KB Output is correct
50 Correct 68 ms 6956 KB Output is correct
51 Correct 45 ms 5288 KB Output is correct
52 Correct 54 ms 7004 KB Output is correct
53 Correct 43 ms 6968 KB Output is correct
54 Correct 48 ms 7740 KB Output is correct
55 Correct 73 ms 7764 KB Output is correct