# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1057157 | 2024-08-13T14:36:02 Z | vjudge1 | Global Warming (CEOI18_glo) | C++17 | 91 ms | 17392 KB |
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 1e6 + 5; #define ALL(a) (a).begin(), (a).end() #define LB(a, x) (lower_bound(ALL(a), x) - (a).begin() + 1) struct fenwick0 { int tree[MAXN]; void update(int x, int v) { for(; x < MAXN; x += (x & -x)) tree[x] = max(tree[x], v); } int get(int x) { int res = 0; for(; x; x -= (x & -x)) res = max(res, tree[x]); return res; } } bit0; struct fenwick1 { int tree[MAXN]; void update(int x, int v) { for(; x; x -= (x & -x)) tree[x] = max(tree[x], v); } int get(int x) { int res = 0; for(; x < MAXN; x += (x & -x)) res = max(res, tree[x]); return res; } } bit1; int N, K; int a[MAXN]; int b[MAXN]; int dp[MAXN]; void compress() { vector<int> temp; for(int i = 1; i <= N; i++) { temp.emplace_back(a[i]); temp.emplace_back(b[i]); } sort(ALL(temp)); temp.resize(unique(ALL(temp)) - temp.begin()); for(int i = 1; i <= N; i++) { a[i] = LB(temp, a[i]); b[i] = LB(temp, b[i]); } } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> K; for(int i = 1; i <= N; i++) cin >> a[i]; for(int i = 1; i <= N; i++) b[i] = a[i] + K; compress(); for(int i = 1; i <= N; i++) { dp[i] = bit0.get(a[i] - 1) + 1; bit0.update(a[i], dp[i]); } int ans = dp[N]; for(int i = N; i >= 1; i--) { ans = max(ans, dp[i] + bit1.get(a[i] + 1)); int cur = bit1.get(b[i] + 1); bit1.update(b[i], cur + 1); } cout << ans; return (0 ^ 0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 0 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6608 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 0 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6608 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6488 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 0 ms | 6492 KB | Output is correct |
17 | Correct | 0 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 0 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6608 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6488 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 0 ms | 6492 KB | Output is correct |
17 | Correct | 0 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6488 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 79 ms | 15784 KB | Output is correct |
2 | Correct | 81 ms | 15788 KB | Output is correct |
3 | Correct | 83 ms | 15844 KB | Output is correct |
4 | Correct | 80 ms | 15788 KB | Output is correct |
5 | Correct | 49 ms | 14492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 9808 KB | Output is correct |
2 | Correct | 19 ms | 9800 KB | Output is correct |
3 | Correct | 19 ms | 9812 KB | Output is correct |
4 | Correct | 13 ms | 9300 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 12 ms | 9404 KB | Output is correct |
7 | Correct | 19 ms | 9664 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 12232 KB | Output is correct |
2 | Correct | 43 ms | 12340 KB | Output is correct |
3 | Correct | 91 ms | 16360 KB | Output is correct |
4 | Correct | 50 ms | 14504 KB | Output is correct |
5 | Correct | 26 ms | 11976 KB | Output is correct |
6 | Correct | 44 ms | 15608 KB | Output is correct |
7 | Correct | 45 ms | 16316 KB | Output is correct |
8 | Correct | 35 ms | 12228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 0 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6492 KB | Output is correct |
8 | Correct | 1 ms | 6492 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6608 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6488 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 0 ms | 6492 KB | Output is correct |
17 | Correct | 0 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 1 ms | 6492 KB | Output is correct |
21 | Correct | 1 ms | 6492 KB | Output is correct |
22 | Correct | 1 ms | 6492 KB | Output is correct |
23 | Correct | 1 ms | 6492 KB | Output is correct |
24 | Correct | 1 ms | 6492 KB | Output is correct |
25 | Correct | 1 ms | 6488 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 79 ms | 15784 KB | Output is correct |
28 | Correct | 81 ms | 15788 KB | Output is correct |
29 | Correct | 83 ms | 15844 KB | Output is correct |
30 | Correct | 80 ms | 15788 KB | Output is correct |
31 | Correct | 49 ms | 14492 KB | Output is correct |
32 | Correct | 19 ms | 9808 KB | Output is correct |
33 | Correct | 19 ms | 9800 KB | Output is correct |
34 | Correct | 19 ms | 9812 KB | Output is correct |
35 | Correct | 13 ms | 9300 KB | Output is correct |
36 | Correct | 1 ms | 6492 KB | Output is correct |
37 | Correct | 12 ms | 9404 KB | Output is correct |
38 | Correct | 19 ms | 9664 KB | Output is correct |
39 | Correct | 43 ms | 12232 KB | Output is correct |
40 | Correct | 43 ms | 12340 KB | Output is correct |
41 | Correct | 91 ms | 16360 KB | Output is correct |
42 | Correct | 50 ms | 14504 KB | Output is correct |
43 | Correct | 26 ms | 11976 KB | Output is correct |
44 | Correct | 44 ms | 15608 KB | Output is correct |
45 | Correct | 45 ms | 16316 KB | Output is correct |
46 | Correct | 35 ms | 12228 KB | Output is correct |
47 | Correct | 41 ms | 12732 KB | Output is correct |
48 | Correct | 41 ms | 12856 KB | Output is correct |
49 | Correct | 87 ms | 17392 KB | Output is correct |
50 | Correct | 47 ms | 14936 KB | Output is correct |
51 | Correct | 40 ms | 14384 KB | Output is correct |
52 | Correct | 48 ms | 14984 KB | Output is correct |
53 | Correct | 44 ms | 15788 KB | Output is correct |
54 | Correct | 48 ms | 16552 KB | Output is correct |
55 | Correct | 70 ms | 16816 KB | Output is correct |