Submission #1014831

# Submission time Handle Problem Language Result Execution time Memory
1014831 2024-07-05T15:16:27 Z aufan Global Warming (CEOI18_glo) C++17
10 / 100
318 ms 42360 KB
#include <bits/stdc++.h>
// #define int long long
#define fi first
#define se second

using namespace std;

const int inf = 1e9;

struct node {
        int val;
        int st, en;
        node *left, *right;

        void build(int start, int end) {
                st = start;
                en = end;

                if (st == en) {
                        val = 0;
                        return;
                }

                int md = (st + en) / 2;
                left = new node();
                right = new node();

                left->build(st, md);
                right->build(md + 1, en);

                val = max(left->val, right->val);
        }

        int query(int lf, int rg) {
                if (st > rg || en < lf) return 0ll;
                if (lf <= st && en <= rg) return val;
                return max(left->query(lf, rg), right->query(lf, rg));
        }

        void update(int id, int x) {
                if (st > id || en < id) return;
                if (st == en) {
                        val = max(val, x);
                        return;
                }

                left->update(id, x);
                right->update(id, x);

                val = max(left->val, right->val);
        }
} sg, sg2;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n, x;
        cin >> n >> x;

        vector<int> a(n + 1), b;
        for (int i = 1; i <= n; i++) {
                cin >> a[i];

                b.push_back(a[i]);
        }
        sort(b.begin(), b.end());
        b.erase(unique(b.begin(), b.end()), b.end());

        auto get = [&](int x) {
                return upper_bound(b.begin(), b.end(), x) - b.begin();
        };

        int m = (int)b.size();
        vector<int> dp(n + 1);
        sg.build(1, m);
        for (int i = n; i >= 1; i--) {
                dp[i] = sg.query(get(a[i]) + 1, m) + 1;
                sg.update(get(a[i]), dp[i]);
        }

        int ans = 0;
        sg2.build(1, m);
        for (int i = 1; i <= n; i++) {
                ans = max(ans, dp[i] + sg2.query(1, get(a[i] - 1 + x)));
                sg2.update(a[i], sg2.query(1, get(a[i]) - 1) + 1);
        }

        cout << ans << '\n';
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 318 ms 42360 KB Output is correct
2 Correct 302 ms 42236 KB Output is correct
3 Correct 280 ms 42188 KB Output is correct
4 Correct 303 ms 42192 KB Output is correct
5 Correct 100 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 10836 KB Output is correct
2 Correct 67 ms 10832 KB Output is correct
3 Correct 62 ms 10904 KB Output is correct
4 Incorrect 22 ms 5852 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 21284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -