# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1051442 | 2024-08-10T07:00:38 Z | manhlinh1501 | Global Warming (CEOI18_glo) | C++17 | 97 ms | 17396 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 | 6488 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6608 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 | 6488 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6488 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6608 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 | 6488 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 0 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6492 KB | Output is correct |
17 | Correct | 1 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 | 6488 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6608 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 | 6488 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 0 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6492 KB | Output is correct |
17 | Correct | 1 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 | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 78 ms | 15764 KB | Output is correct |
2 | Correct | 79 ms | 15772 KB | Output is correct |
3 | Correct | 79 ms | 15784 KB | Output is correct |
4 | Correct | 83 ms | 15856 KB | Output is correct |
5 | Correct | 44 ms | 14592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 9812 KB | Output is correct |
2 | Correct | 19 ms | 9652 KB | Output is correct |
3 | Correct | 19 ms | 9812 KB | Output is correct |
4 | Correct | 11 ms | 9300 KB | Output is correct |
5 | Correct | 1 ms | 6492 KB | Output is correct |
6 | Correct | 10 ms | 9404 KB | Output is correct |
7 | Correct | 16 ms | 9812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 12476 KB | Output is correct |
2 | Correct | 43 ms | 12224 KB | Output is correct |
3 | Correct | 97 ms | 16412 KB | Output is correct |
4 | Correct | 51 ms | 14508 KB | Output is correct |
5 | Correct | 26 ms | 11964 KB | Output is correct |
6 | Correct | 43 ms | 15648 KB | Output is correct |
7 | Correct | 45 ms | 16380 KB | Output is correct |
8 | Correct | 34 ms | 12228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6488 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6608 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 | 6488 KB | Output is correct |
9 | Correct | 1 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 0 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 1 ms | 6492 KB | Output is correct |
16 | Correct | 1 ms | 6492 KB | Output is correct |
17 | Correct | 1 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 | 6492 KB | Output is correct |
26 | Correct | 1 ms | 6492 KB | Output is correct |
27 | Correct | 78 ms | 15764 KB | Output is correct |
28 | Correct | 79 ms | 15772 KB | Output is correct |
29 | Correct | 79 ms | 15784 KB | Output is correct |
30 | Correct | 83 ms | 15856 KB | Output is correct |
31 | Correct | 44 ms | 14592 KB | Output is correct |
32 | Correct | 19 ms | 9812 KB | Output is correct |
33 | Correct | 19 ms | 9652 KB | Output is correct |
34 | Correct | 19 ms | 9812 KB | Output is correct |
35 | Correct | 11 ms | 9300 KB | Output is correct |
36 | Correct | 1 ms | 6492 KB | Output is correct |
37 | Correct | 10 ms | 9404 KB | Output is correct |
38 | Correct | 16 ms | 9812 KB | Output is correct |
39 | Correct | 42 ms | 12476 KB | Output is correct |
40 | Correct | 43 ms | 12224 KB | Output is correct |
41 | Correct | 97 ms | 16412 KB | Output is correct |
42 | Correct | 51 ms | 14508 KB | Output is correct |
43 | Correct | 26 ms | 11964 KB | Output is correct |
44 | Correct | 43 ms | 15648 KB | Output is correct |
45 | Correct | 45 ms | 16380 KB | Output is correct |
46 | Correct | 34 ms | 12228 KB | Output is correct |
47 | Correct | 40 ms | 12728 KB | Output is correct |
48 | Correct | 41 ms | 12848 KB | Output is correct |
49 | Correct | 85 ms | 17396 KB | Output is correct |
50 | Correct | 47 ms | 15016 KB | Output is correct |
51 | Correct | 35 ms | 14400 KB | Output is correct |
52 | Correct | 46 ms | 15204 KB | Output is correct |
53 | Correct | 44 ms | 15784 KB | Output is correct |
54 | Correct | 48 ms | 16440 KB | Output is correct |
55 | Correct | 68 ms | 16808 KB | Output is correct |