//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
const ll INF = (ll) 1e18 + 1e9;
struct SegTree {
vector<int> t;
int sz;
SegTree(int n) {
sz = n;
t.resize(sz << 1);
}
void upd(int i, int v) {
i += sz;
t[i] = v;
i >>= 1;
while (i) {
t[i] = max(t[i << 1], t[i << 1 | 1]);
i >>= 1;
}
}
int get(int l, int r) {
l += sz;
r += sz;
int ret = 0;
while (l < r) {
if (l & 1) ret = max(ret, t[l++]);
if (r & 1) ret = max(ret, t[--r]);
l >>= 1;
r >>= 1;
}
return ret;
}
};
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<ll> a(n), srt;
for (int i = 0; i < n; ++i) {
cin >> a[i];
srt.push_back(a[i]);
srt.push_back(a[i] - x);
}
sort(srt.begin(), srt.end());
srt.resize(unique(srt.begin(), srt.end()) - srt.begin());
SegTree st(srt.size());
vector<ll> dp(n + 1, INF);
dp[0] = -INF;
int mx = 0;
for (auto v : a) {
int pos = lower_bound(srt.begin(), srt.end(), v) - srt.begin(),
cnt = lower_bound(dp.begin(), dp.end(), v) - dp.begin(),
cur = max(st.get(0, pos) + 1, cnt);
mx = max({mx, cur});
st.upd(pos, cur);
dp[lower_bound(dp.begin(), dp.end(), v - x) - dp.begin()] = v - x;
}
cout << mx;
}
/*
*/
# |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
8600 KB |
Output is correct |
2 |
Correct |
121 ms |
8256 KB |
Output is correct |
3 |
Correct |
117 ms |
8140 KB |
Output is correct |
4 |
Correct |
116 ms |
8100 KB |
Output is correct |
5 |
Correct |
54 ms |
7368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
2772 KB |
Output is correct |
2 |
Correct |
28 ms |
2776 KB |
Output is correct |
3 |
Correct |
28 ms |
2776 KB |
Output is correct |
4 |
Correct |
14 ms |
2292 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
16 ms |
2576 KB |
Output is correct |
7 |
Correct |
24 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
5152 KB |
Output is correct |
2 |
Correct |
63 ms |
6100 KB |
Output is correct |
3 |
Correct |
121 ms |
11776 KB |
Output is correct |
4 |
Correct |
66 ms |
9412 KB |
Output is correct |
5 |
Correct |
38 ms |
5584 KB |
Output is correct |
6 |
Correct |
68 ms |
10436 KB |
Output is correct |
7 |
Correct |
70 ms |
11208 KB |
Output is correct |
8 |
Correct |
49 ms |
6344 KB |
Output is correct |
# |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
121 ms |
8600 KB |
Output is correct |
28 |
Correct |
121 ms |
8256 KB |
Output is correct |
29 |
Correct |
117 ms |
8140 KB |
Output is correct |
30 |
Correct |
116 ms |
8100 KB |
Output is correct |
31 |
Correct |
54 ms |
7368 KB |
Output is correct |
32 |
Correct |
30 ms |
2772 KB |
Output is correct |
33 |
Correct |
28 ms |
2776 KB |
Output is correct |
34 |
Correct |
28 ms |
2776 KB |
Output is correct |
35 |
Correct |
14 ms |
2292 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
16 ms |
2576 KB |
Output is correct |
38 |
Correct |
24 ms |
3288 KB |
Output is correct |
39 |
Correct |
56 ms |
5152 KB |
Output is correct |
40 |
Correct |
63 ms |
6100 KB |
Output is correct |
41 |
Correct |
121 ms |
11776 KB |
Output is correct |
42 |
Correct |
66 ms |
9412 KB |
Output is correct |
43 |
Correct |
38 ms |
5584 KB |
Output is correct |
44 |
Correct |
68 ms |
10436 KB |
Output is correct |
45 |
Correct |
70 ms |
11208 KB |
Output is correct |
46 |
Correct |
49 ms |
6344 KB |
Output is correct |
47 |
Correct |
59 ms |
6088 KB |
Output is correct |
48 |
Correct |
58 ms |
6092 KB |
Output is correct |
49 |
Correct |
123 ms |
11788 KB |
Output is correct |
50 |
Correct |
57 ms |
9412 KB |
Output is correct |
51 |
Correct |
61 ms |
8348 KB |
Output is correct |
52 |
Correct |
73 ms |
9788 KB |
Output is correct |
53 |
Correct |
72 ms |
11976 KB |
Output is correct |
54 |
Correct |
72 ms |
11720 KB |
Output is correct |
55 |
Correct |
105 ms |
11288 KB |
Output is correct |