#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, x;
int a[N], ft[2][N];
int qry(int i, int *s) {
int res = 0;
for (; i; i -= i & -i) {
res = max(res, s[i]);
}
return res;
}
void upd(int i, int x, int *s) {
for (; i < N; i += i & -i) {
s[i] = max(s[i], x);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> x;
vector<int> comp;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
comp.push_back(a[i]);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
auto id = [&](int x) {
return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1;
};
int res = 0;
for (int i = 1; i <= n; ++i) {
array<int, 2> dp{};
int p = id(a[i]);
dp[0] = qry(p - 1, ft[0]) + 1;
dp[1] = max(qry(p - 1, ft[1]), qry(id(a[i] + x) - 1, ft[0])) + 1;
upd(p, dp[0], ft[0]);
upd(p, dp[1], ft[1]);
res = max(res, dp[1]);
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
488 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
488 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
23 |
Correct |
1 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
5636 KB |
Output is correct |
2 |
Correct |
85 ms |
5580 KB |
Output is correct |
3 |
Correct |
84 ms |
5588 KB |
Output is correct |
4 |
Correct |
89 ms |
5448 KB |
Output is correct |
5 |
Correct |
34 ms |
4072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1756 KB |
Output is correct |
2 |
Correct |
19 ms |
1760 KB |
Output is correct |
3 |
Correct |
19 ms |
1756 KB |
Output is correct |
4 |
Correct |
10 ms |
1428 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
1472 KB |
Output is correct |
7 |
Correct |
20 ms |
1752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
3036 KB |
Output is correct |
2 |
Correct |
34 ms |
3032 KB |
Output is correct |
3 |
Correct |
69 ms |
5632 KB |
Output is correct |
4 |
Correct |
38 ms |
3980 KB |
Output is correct |
5 |
Correct |
18 ms |
2524 KB |
Output is correct |
6 |
Correct |
35 ms |
4556 KB |
Output is correct |
7 |
Correct |
38 ms |
5400 KB |
Output is correct |
8 |
Correct |
28 ms |
3036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
488 KB |
Output is correct |
12 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
23 |
Correct |
1 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 |
344 KB |
Output is correct |
27 |
Correct |
87 ms |
5636 KB |
Output is correct |
28 |
Correct |
85 ms |
5580 KB |
Output is correct |
29 |
Correct |
84 ms |
5588 KB |
Output is correct |
30 |
Correct |
89 ms |
5448 KB |
Output is correct |
31 |
Correct |
34 ms |
4072 KB |
Output is correct |
32 |
Correct |
21 ms |
1756 KB |
Output is correct |
33 |
Correct |
19 ms |
1760 KB |
Output is correct |
34 |
Correct |
19 ms |
1756 KB |
Output is correct |
35 |
Correct |
10 ms |
1428 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
9 ms |
1472 KB |
Output is correct |
38 |
Correct |
20 ms |
1752 KB |
Output is correct |
39 |
Correct |
32 ms |
3036 KB |
Output is correct |
40 |
Correct |
34 ms |
3032 KB |
Output is correct |
41 |
Correct |
69 ms |
5632 KB |
Output is correct |
42 |
Correct |
38 ms |
3980 KB |
Output is correct |
43 |
Correct |
18 ms |
2524 KB |
Output is correct |
44 |
Correct |
35 ms |
4556 KB |
Output is correct |
45 |
Correct |
38 ms |
5400 KB |
Output is correct |
46 |
Correct |
28 ms |
3036 KB |
Output is correct |
47 |
Correct |
38 ms |
3032 KB |
Output is correct |
48 |
Correct |
45 ms |
3024 KB |
Output is correct |
49 |
Correct |
87 ms |
5580 KB |
Output is correct |
50 |
Correct |
38 ms |
4048 KB |
Output is correct |
51 |
Correct |
32 ms |
3280 KB |
Output is correct |
52 |
Correct |
48 ms |
4968 KB |
Output is correct |
53 |
Correct |
36 ms |
4812 KB |
Output is correct |
54 |
Correct |
43 ms |
5584 KB |
Output is correct |
55 |
Correct |
69 ms |
5580 KB |
Output is correct |