#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 4e5 + 5;
int a[N], c[N];
int n, d, m = 0;
struct BIT {
int bit[N];
int get(int i) {
i = upper_bound(c, c + m, i) - c;
int res = 0;
for (; i; i -= i & -i) {
res = max(res, bit[i]);
}
return res;
}
void update(int i, int v) {
i = lower_bound(c, c + m, i) - c + 1;
for (; i <= m; i += i & -i) {
bit[i] = max(bit[i], v);
}
}
} bit1, bit2;
int f[N][2];
int main() {
cin.tie(0)->sync_with_stdio(0); cout.tie(0);
cin >> n >> d;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
c[m++] = a[i];
}
sort(c, c + m);
m = unique(c, c + m) - c;
int res = 0;
for (int i = 1; i <= n; ++i) {
f[i][0] = bit1.get(a[i] - 1) + 1;
f[i][1] = max(bit2.get(a[i] - 1) + 1, bit1.get(a[i] + d - 1) + 1);
bit1.update(a[i], f[i][0]);
bit2.update(a[i], f[i][1]);
res = max(res, f[i][0]);
res = max(res, f[i][1]);
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 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 |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
296 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
6920 KB |
Output is correct |
2 |
Correct |
160 ms |
6904 KB |
Output is correct |
3 |
Correct |
156 ms |
6860 KB |
Output is correct |
4 |
Correct |
159 ms |
6988 KB |
Output is correct |
5 |
Correct |
72 ms |
5328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
1984 KB |
Output is correct |
2 |
Correct |
35 ms |
1952 KB |
Output is correct |
3 |
Correct |
36 ms |
1948 KB |
Output is correct |
4 |
Correct |
17 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
21 ms |
1596 KB |
Output is correct |
7 |
Correct |
30 ms |
1988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
3568 KB |
Output is correct |
2 |
Correct |
67 ms |
3532 KB |
Output is correct |
3 |
Correct |
142 ms |
6936 KB |
Output is correct |
4 |
Correct |
67 ms |
5316 KB |
Output is correct |
5 |
Correct |
39 ms |
3200 KB |
Output is correct |
6 |
Correct |
69 ms |
6076 KB |
Output is correct |
7 |
Correct |
84 ms |
6648 KB |
Output is correct |
8 |
Correct |
54 ms |
3656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 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 |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
296 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
159 ms |
6920 KB |
Output is correct |
28 |
Correct |
160 ms |
6904 KB |
Output is correct |
29 |
Correct |
156 ms |
6860 KB |
Output is correct |
30 |
Correct |
159 ms |
6988 KB |
Output is correct |
31 |
Correct |
72 ms |
5328 KB |
Output is correct |
32 |
Correct |
39 ms |
1984 KB |
Output is correct |
33 |
Correct |
35 ms |
1952 KB |
Output is correct |
34 |
Correct |
36 ms |
1948 KB |
Output is correct |
35 |
Correct |
17 ms |
1620 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
21 ms |
1596 KB |
Output is correct |
38 |
Correct |
30 ms |
1988 KB |
Output is correct |
39 |
Correct |
66 ms |
3568 KB |
Output is correct |
40 |
Correct |
67 ms |
3532 KB |
Output is correct |
41 |
Correct |
142 ms |
6936 KB |
Output is correct |
42 |
Correct |
67 ms |
5316 KB |
Output is correct |
43 |
Correct |
39 ms |
3200 KB |
Output is correct |
44 |
Correct |
69 ms |
6076 KB |
Output is correct |
45 |
Correct |
84 ms |
6648 KB |
Output is correct |
46 |
Correct |
54 ms |
3656 KB |
Output is correct |
47 |
Correct |
78 ms |
3624 KB |
Output is correct |
48 |
Correct |
79 ms |
3588 KB |
Output is correct |
49 |
Correct |
163 ms |
6872 KB |
Output is correct |
50 |
Correct |
71 ms |
5388 KB |
Output is correct |
51 |
Correct |
63 ms |
4396 KB |
Output is correct |
52 |
Correct |
97 ms |
6176 KB |
Output is correct |
53 |
Correct |
75 ms |
6204 KB |
Output is correct |
54 |
Correct |
75 ms |
6880 KB |
Output is correct |
55 |
Correct |
130 ms |
6884 KB |
Output is correct |