Submission #1014830

# Submission time Handle Problem Language Result Execution time Memory
1014830 2024-07-05T15:11:45 Z aufan Global Warming (CEOI18_glo) C++17
48 / 100
367 ms 262144 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;

                val = 0;
        }

        void lazy() {
                if (left == NULL) {
                        int md = (st + en) / 2;
                        left = new node();
                        right = new node();

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

        int query(int lf, int rg) {
                if (st > rg || en < lf || lf > rg) return 0ll;
                if (lf <= st && en <= rg) return val;
                if (left == NULL) return 0ll;
                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;
                }

                lazy();
                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);
        for (int i = 1; i <= n; i++) cin >> a[i];

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

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

        cout << ans << '\n';
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 4188 KB Output is correct
20 Correct 4 ms 4188 KB Output is correct
21 Correct 4 ms 4188 KB Output is correct
22 Correct 4 ms 4188 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2392 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 367 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 202 ms 136528 KB Output is correct
2 Correct 173 ms 136528 KB Output is correct
3 Correct 173 ms 136444 KB Output is correct
4 Correct 91 ms 73312 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 42 ms 10324 KB Output is correct
7 Correct 117 ms 94652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 254156 KB Output is correct
2 Correct 332 ms 253776 KB Output is correct
3 Runtime error 365 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 7 ms 4188 KB Output is correct
20 Correct 4 ms 4188 KB Output is correct
21 Correct 4 ms 4188 KB Output is correct
22 Correct 4 ms 4188 KB Output is correct
23 Correct 3 ms 2396 KB Output is correct
24 Correct 3 ms 2392 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 452 KB Output is correct
27 Runtime error 367 ms 262144 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -