#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define fi first
#define se second
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;
/** END OF TEMPLATE **/
const int mxN = 2e5 + 5;
int n, d;
int f1[mxN], f2[mxN], a[mxN], b[mxN];
struct fenwick {
vector<int> bit;
fenwick(int t) { bit.resize(t + 1, 0); }
void update(int id, int val) {
for(; id <= 2*n; id += id&-id) bit[id] = max(bit[id], val);
}
ll get(int id) {
int temp = 0;
for(; id > 0; id -= id&-id) temp = max(temp, bit[id]);
return temp;
}
};
int main()
{
FastIO;
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
cin >> n >> d;
vector<int> t;
FOR(i, 1, n) {
cin >> a[i];
t.PB(a[i]); t.PB(a[i] + d);
}
sort(ALL(t));
FOR(i, 1, n)
b[i] = lower_bound(ALL(t), a[i] + d) - t.begin() + 1,
a[i] = lower_bound(ALL(t), a[i]) - t.begin() + 1;
fenwick T1(2*n+1);
FOR(i, 1, n) {
f1[i] = T1.get(a[i]-1) + 1;
T1.update(a[i], f1[i]);
}
fenwick T(2*n+1);
FOR(i, 1, n) {
f2[i] = T.get(b[i] - 1) + 1;
T.update(a[i], f1[i]);
T.update(b[i], f2[i]);
}
int res = 0;
FOR(i, 1, n)
res = max(res, max(f1[i], f2[i]));
cout << res;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
8232 KB |
Output is correct |
2 |
Correct |
116 ms |
8180 KB |
Output is correct |
3 |
Correct |
117 ms |
8184 KB |
Output is correct |
4 |
Correct |
114 ms |
8164 KB |
Output is correct |
5 |
Correct |
61 ms |
8332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2352 KB |
Output is correct |
2 |
Correct |
28 ms |
2404 KB |
Output is correct |
3 |
Correct |
26 ms |
2400 KB |
Output is correct |
4 |
Correct |
15 ms |
2448 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
16 ms |
2644 KB |
Output is correct |
7 |
Correct |
24 ms |
2856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
4276 KB |
Output is correct |
2 |
Correct |
60 ms |
5320 KB |
Output is correct |
3 |
Correct |
127 ms |
10100 KB |
Output is correct |
4 |
Correct |
73 ms |
9472 KB |
Output is correct |
5 |
Correct |
37 ms |
4940 KB |
Output is correct |
6 |
Correct |
62 ms |
9028 KB |
Output is correct |
7 |
Correct |
66 ms |
9664 KB |
Output is correct |
8 |
Correct |
48 ms |
5304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
119 ms |
8232 KB |
Output is correct |
28 |
Correct |
116 ms |
8180 KB |
Output is correct |
29 |
Correct |
117 ms |
8184 KB |
Output is correct |
30 |
Correct |
114 ms |
8164 KB |
Output is correct |
31 |
Correct |
61 ms |
8332 KB |
Output is correct |
32 |
Correct |
27 ms |
2352 KB |
Output is correct |
33 |
Correct |
28 ms |
2404 KB |
Output is correct |
34 |
Correct |
26 ms |
2400 KB |
Output is correct |
35 |
Correct |
15 ms |
2448 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
16 ms |
2644 KB |
Output is correct |
38 |
Correct |
24 ms |
2856 KB |
Output is correct |
39 |
Correct |
57 ms |
4276 KB |
Output is correct |
40 |
Correct |
60 ms |
5320 KB |
Output is correct |
41 |
Correct |
127 ms |
10100 KB |
Output is correct |
42 |
Correct |
73 ms |
9472 KB |
Output is correct |
43 |
Correct |
37 ms |
4940 KB |
Output is correct |
44 |
Correct |
62 ms |
9028 KB |
Output is correct |
45 |
Correct |
66 ms |
9664 KB |
Output is correct |
46 |
Correct |
48 ms |
5304 KB |
Output is correct |
47 |
Correct |
56 ms |
5336 KB |
Output is correct |
48 |
Correct |
66 ms |
5232 KB |
Output is correct |
49 |
Correct |
119 ms |
10176 KB |
Output is correct |
50 |
Correct |
65 ms |
9392 KB |
Output is correct |
51 |
Correct |
53 ms |
7128 KB |
Output is correct |
52 |
Correct |
73 ms |
9500 KB |
Output is correct |
53 |
Correct |
69 ms |
9620 KB |
Output is correct |
54 |
Correct |
70 ms |
10180 KB |
Output is correct |
55 |
Correct |
98 ms |
10148 KB |
Output is correct |