#include <bits/stdc++.h>
#define ll long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 4e5 + 2;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int base = 311;
const int BLOCK_SIZE = 2000;
int n, x;
struct tree {
int bit[N] = {0};
void upd(int idx, int v) {
for (; idx <= 2 * n; idx += idx & -idx)
bit[idx] = max(bit[idx], v);
}
int get(int idx) {
int ans = 0;
for (; idx > 0; idx -= idx & -idx)
ans = max(ans, bit[idx]);
return ans;
}
} bit0, bit1;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> x;
vector <int> a(n), b;
for (int i = 0; i < n; i ++) {
cin >> a[i];
b.push_back(a[i]);
b.push_back(a[i] + x);
}
sort(all(b));
b.erase(unique(all(b)), b.end());
for (int i = 0; i < n; i ++) {
int ac = lower_bound(all(b), a[i] + x) - b.begin() + 1;
a[i] = lower_bound(all(b), a[i]) - b.begin() + 1;
int res = bit0.get(a[i] - 1) + 1;
int res2 = max(bit0.get(ac - 1), bit1.get(a[i] - 1)) + 1;
bit0.upd(a[i], res);
bit1.upd(a[i], res2);
}
cout << bit1.get(2 * n);
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
4376 KB |
Output is correct |
2 |
Correct |
121 ms |
4408 KB |
Output is correct |
3 |
Correct |
123 ms |
4356 KB |
Output is correct |
4 |
Correct |
146 ms |
4344 KB |
Output is correct |
5 |
Correct |
59 ms |
3608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1848 KB |
Output is correct |
2 |
Correct |
33 ms |
1748 KB |
Output is correct |
3 |
Correct |
29 ms |
1824 KB |
Output is correct |
4 |
Correct |
15 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
16 ms |
1676 KB |
Output is correct |
7 |
Correct |
30 ms |
2088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
2384 KB |
Output is correct |
2 |
Correct |
61 ms |
2420 KB |
Output is correct |
3 |
Correct |
129 ms |
4340 KB |
Output is correct |
4 |
Correct |
73 ms |
3636 KB |
Output is correct |
5 |
Correct |
39 ms |
2388 KB |
Output is correct |
6 |
Correct |
64 ms |
4112 KB |
Output is correct |
7 |
Correct |
70 ms |
4208 KB |
Output is correct |
8 |
Correct |
56 ms |
2344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
131 ms |
4376 KB |
Output is correct |
28 |
Correct |
121 ms |
4408 KB |
Output is correct |
29 |
Correct |
123 ms |
4356 KB |
Output is correct |
30 |
Correct |
146 ms |
4344 KB |
Output is correct |
31 |
Correct |
59 ms |
3608 KB |
Output is correct |
32 |
Correct |
27 ms |
1848 KB |
Output is correct |
33 |
Correct |
33 ms |
1748 KB |
Output is correct |
34 |
Correct |
29 ms |
1824 KB |
Output is correct |
35 |
Correct |
15 ms |
1364 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
16 ms |
1676 KB |
Output is correct |
38 |
Correct |
30 ms |
2088 KB |
Output is correct |
39 |
Correct |
59 ms |
2384 KB |
Output is correct |
40 |
Correct |
61 ms |
2420 KB |
Output is correct |
41 |
Correct |
129 ms |
4340 KB |
Output is correct |
42 |
Correct |
73 ms |
3636 KB |
Output is correct |
43 |
Correct |
39 ms |
2388 KB |
Output is correct |
44 |
Correct |
64 ms |
4112 KB |
Output is correct |
45 |
Correct |
70 ms |
4208 KB |
Output is correct |
46 |
Correct |
56 ms |
2344 KB |
Output is correct |
47 |
Correct |
64 ms |
3652 KB |
Output is correct |
48 |
Correct |
64 ms |
3592 KB |
Output is correct |
49 |
Correct |
128 ms |
6328 KB |
Output is correct |
50 |
Correct |
64 ms |
4840 KB |
Output is correct |
51 |
Correct |
54 ms |
3564 KB |
Output is correct |
52 |
Correct |
72 ms |
4888 KB |
Output is correct |
53 |
Correct |
66 ms |
4816 KB |
Output is correct |
54 |
Correct |
75 ms |
4920 KB |
Output is correct |
55 |
Correct |
109 ms |
5956 KB |
Output is correct |