#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e15;
lint N, X;
lint A[200005];
lint lis[200005];
lint lds[200005];
lint anslis[200005];
lint LIS() {
for (int i = 0; i <= N; i++) lis[i] = INF, lds[i] = -INF;
lis[0] = -INF, lds[N] = INF;
lint res = 0;
for (lint i = 0; i < N; i++) {
lint j = lower_bound(lis, lis + N + 1, A[i]) - lis;
lis[j] = A[i], res = max(res, j);
anslis[i] = j;
}
for (lint i = N - 1; i >= 0; i--) {
lint j = upper_bound(lds, lds + N + 1, A[i] - X) - lds;
res = max(res, anslis[i] + N - j);
j = upper_bound(lds, lds + N + 1, A[i]) - lds - 1;
lds[j] = A[i];
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> X;
for (int i = 0; i < N; i++) cin >> A[i];
lint ans = LIS();
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
388 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
388 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
388 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
396 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
7160 KB |
Output is correct |
2 |
Correct |
82 ms |
7132 KB |
Output is correct |
3 |
Correct |
83 ms |
7160 KB |
Output is correct |
4 |
Correct |
83 ms |
7032 KB |
Output is correct |
5 |
Correct |
64 ms |
7032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2424 KB |
Output is correct |
2 |
Correct |
25 ms |
2424 KB |
Output is correct |
3 |
Correct |
21 ms |
2424 KB |
Output is correct |
4 |
Correct |
17 ms |
2168 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
18 ms |
2200 KB |
Output is correct |
7 |
Correct |
18 ms |
2424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
3964 KB |
Output is correct |
2 |
Correct |
37 ms |
3960 KB |
Output is correct |
3 |
Correct |
82 ms |
7168 KB |
Output is correct |
4 |
Correct |
61 ms |
7032 KB |
Output is correct |
5 |
Correct |
34 ms |
4108 KB |
Output is correct |
6 |
Correct |
56 ms |
7416 KB |
Output is correct |
7 |
Correct |
64 ms |
8292 KB |
Output is correct |
8 |
Correct |
35 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
388 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
396 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
85 ms |
7160 KB |
Output is correct |
28 |
Correct |
82 ms |
7132 KB |
Output is correct |
29 |
Correct |
83 ms |
7160 KB |
Output is correct |
30 |
Correct |
83 ms |
7032 KB |
Output is correct |
31 |
Correct |
64 ms |
7032 KB |
Output is correct |
32 |
Correct |
20 ms |
2424 KB |
Output is correct |
33 |
Correct |
25 ms |
2424 KB |
Output is correct |
34 |
Correct |
21 ms |
2424 KB |
Output is correct |
35 |
Correct |
17 ms |
2168 KB |
Output is correct |
36 |
Correct |
2 ms |
380 KB |
Output is correct |
37 |
Correct |
18 ms |
2200 KB |
Output is correct |
38 |
Correct |
18 ms |
2424 KB |
Output is correct |
39 |
Correct |
37 ms |
3964 KB |
Output is correct |
40 |
Correct |
37 ms |
3960 KB |
Output is correct |
41 |
Correct |
82 ms |
7168 KB |
Output is correct |
42 |
Correct |
61 ms |
7032 KB |
Output is correct |
43 |
Correct |
34 ms |
4108 KB |
Output is correct |
44 |
Correct |
56 ms |
7416 KB |
Output is correct |
45 |
Correct |
64 ms |
8292 KB |
Output is correct |
46 |
Correct |
35 ms |
4472 KB |
Output is correct |
47 |
Correct |
41 ms |
4456 KB |
Output is correct |
48 |
Correct |
44 ms |
4472 KB |
Output is correct |
49 |
Correct |
85 ms |
8528 KB |
Output is correct |
50 |
Correct |
62 ms |
7800 KB |
Output is correct |
51 |
Correct |
49 ms |
5880 KB |
Output is correct |
52 |
Correct |
67 ms |
7876 KB |
Output is correct |
53 |
Correct |
62 ms |
7800 KB |
Output is correct |
54 |
Correct |
67 ms |
8824 KB |
Output is correct |
55 |
Correct |
72 ms |
8568 KB |
Output is correct |