#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }
const int N = 200001;
const ll infL = 3e18;
int fn[N], n, a[N], yy[N], aa[N], lis[N], lds[N];
void setmax(int i, int x) {
for (; i < n; i |= i + 1)
fn[i] = max(fn[i], x);
}
int get(int i) {
int ans = 0;
for (; i > -1; i = ((i + 1) & i) - 1)
ans = max(ans, fn[i]);
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int d;
cin >> n >> d;
for (int i = 0; i < n; ++i)
cin >> a[i];
memcpy(yy, a, sizeof(yy[0]) * n);
memcpy(aa, a, sizeof(aa[0]) * n);
sort(yy, yy + n);
int m = unique(yy, yy + n) - yy;
for (int i = 0; i < n; ++i)
a[i] = lower_bound(yy, yy + m, a[i]) - yy;
int ans = 0;
for (int i = n - 1; i > -1; --i) {
lds[i] = get(n - (a[i] + 1) - 1) + 1;
ans = max(ans, lds[i]);
setmax(n - a[i] - 1, lds[i]);
}
memset(fn, 0, sizeof(fn));
for (int i = 0; i < n; ++i) {
int id = lower_bound(yy, yy + m, aa[i] + d) - yy;
ans = max(ans, get(id - 1) + lds[i]);
lis[i] = get(a[i] - 1) + 1;
setmax(a[i], lis[i]);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
2 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
4976 KB |
Output is correct |
2 |
Correct |
103 ms |
4988 KB |
Output is correct |
3 |
Correct |
106 ms |
4988 KB |
Output is correct |
4 |
Correct |
105 ms |
4896 KB |
Output is correct |
5 |
Correct |
51 ms |
4880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
2040 KB |
Output is correct |
2 |
Correct |
23 ms |
2096 KB |
Output is correct |
3 |
Correct |
22 ms |
2004 KB |
Output is correct |
4 |
Correct |
14 ms |
2192 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
12 ms |
2020 KB |
Output is correct |
7 |
Correct |
19 ms |
2004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2992 KB |
Output is correct |
2 |
Correct |
39 ms |
3036 KB |
Output is correct |
3 |
Correct |
78 ms |
4984 KB |
Output is correct |
4 |
Correct |
49 ms |
4988 KB |
Output is correct |
5 |
Correct |
23 ms |
3028 KB |
Output is correct |
6 |
Correct |
43 ms |
4800 KB |
Output is correct |
7 |
Correct |
45 ms |
4812 KB |
Output is correct |
8 |
Correct |
33 ms |
3048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
2 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
109 ms |
4976 KB |
Output is correct |
28 |
Correct |
103 ms |
4988 KB |
Output is correct |
29 |
Correct |
106 ms |
4988 KB |
Output is correct |
30 |
Correct |
105 ms |
4896 KB |
Output is correct |
31 |
Correct |
51 ms |
4880 KB |
Output is correct |
32 |
Correct |
22 ms |
2040 KB |
Output is correct |
33 |
Correct |
23 ms |
2096 KB |
Output is correct |
34 |
Correct |
22 ms |
2004 KB |
Output is correct |
35 |
Correct |
14 ms |
2192 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
12 ms |
2020 KB |
Output is correct |
38 |
Correct |
19 ms |
2004 KB |
Output is correct |
39 |
Correct |
37 ms |
2992 KB |
Output is correct |
40 |
Correct |
39 ms |
3036 KB |
Output is correct |
41 |
Correct |
78 ms |
4984 KB |
Output is correct |
42 |
Correct |
49 ms |
4988 KB |
Output is correct |
43 |
Correct |
23 ms |
3028 KB |
Output is correct |
44 |
Correct |
43 ms |
4800 KB |
Output is correct |
45 |
Correct |
45 ms |
4812 KB |
Output is correct |
46 |
Correct |
33 ms |
3048 KB |
Output is correct |
47 |
Correct |
48 ms |
3044 KB |
Output is correct |
48 |
Correct |
47 ms |
3052 KB |
Output is correct |
49 |
Correct |
102 ms |
4912 KB |
Output is correct |
50 |
Correct |
49 ms |
4952 KB |
Output is correct |
51 |
Correct |
42 ms |
3952 KB |
Output is correct |
52 |
Correct |
64 ms |
5000 KB |
Output is correct |
53 |
Correct |
43 ms |
4980 KB |
Output is correct |
54 |
Correct |
47 ms |
4956 KB |
Output is correct |
55 |
Correct |
81 ms |
4952 KB |
Output is correct |