#include <bits/stdc++.h>
using namespace std;
#define int long long
struct BIT
{
int n;
vector<int> ft;
void init(int N)
{
n = N + 5;
ft.assign(n + 5, 0);
}
void make(int pos, int val)
{
for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] = max(ft[pos], val);
}
int get(int pos, int res = 0)
{
for (pos = pos + 1; pos > 0; pos -= pos & -pos) res = max(res, ft[pos]);
return res;
}
};
vector<int> mp;
int id(int x)
{
return lower_bound(mp.begin(), mp.end(), x) - mp.begin();
}
signed main()
{
int n, d;
cin >> n >> d;
int a[n], b[n];
for (int &i : a)
{
cin >> i;
mp.push_back(i), mp.push_back(i + d);
}
sort(mp.begin(), mp.end());
mp.resize(unique(mp.begin(), mp.end()) - mp.begin());
BIT ft1, ft2;
ft1.init(2*n), ft2.init(2*n);
for (int i = 0; i < n; i++)
{
b[i] = id(a[i] + d);
a[i] = id(a[i]);
int x = ft1.get(a[i] - 1), y = ft1.get(b[i] - 1), z = ft2.get(b[i] - 1);
ft1.make(a[i], x + 1);
ft2.make(b[i], max(y, z) + 1);
}
cout << max(ft1.get(2 * n), ft2.get(2 * n)) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
500 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
500 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
436 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
500 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
436 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
14864 KB |
Output is correct |
2 |
Correct |
149 ms |
14776 KB |
Output is correct |
3 |
Correct |
143 ms |
14772 KB |
Output is correct |
4 |
Correct |
151 ms |
14832 KB |
Output is correct |
5 |
Correct |
79 ms |
14348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
4148 KB |
Output is correct |
2 |
Correct |
34 ms |
4036 KB |
Output is correct |
3 |
Correct |
35 ms |
4168 KB |
Output is correct |
4 |
Correct |
21 ms |
4200 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
20 ms |
3788 KB |
Output is correct |
7 |
Correct |
31 ms |
4048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
7564 KB |
Output is correct |
2 |
Correct |
75 ms |
7580 KB |
Output is correct |
3 |
Correct |
189 ms |
14888 KB |
Output is correct |
4 |
Correct |
84 ms |
14148 KB |
Output is correct |
5 |
Correct |
51 ms |
7360 KB |
Output is correct |
6 |
Correct |
92 ms |
14284 KB |
Output is correct |
7 |
Correct |
97 ms |
14272 KB |
Output is correct |
8 |
Correct |
64 ms |
7816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
500 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
436 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
356 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
142 ms |
14864 KB |
Output is correct |
28 |
Correct |
149 ms |
14776 KB |
Output is correct |
29 |
Correct |
143 ms |
14772 KB |
Output is correct |
30 |
Correct |
151 ms |
14832 KB |
Output is correct |
31 |
Correct |
79 ms |
14348 KB |
Output is correct |
32 |
Correct |
35 ms |
4148 KB |
Output is correct |
33 |
Correct |
34 ms |
4036 KB |
Output is correct |
34 |
Correct |
35 ms |
4168 KB |
Output is correct |
35 |
Correct |
21 ms |
4200 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
20 ms |
3788 KB |
Output is correct |
38 |
Correct |
31 ms |
4048 KB |
Output is correct |
39 |
Correct |
93 ms |
7564 KB |
Output is correct |
40 |
Correct |
75 ms |
7580 KB |
Output is correct |
41 |
Correct |
189 ms |
14888 KB |
Output is correct |
42 |
Correct |
84 ms |
14148 KB |
Output is correct |
43 |
Correct |
51 ms |
7360 KB |
Output is correct |
44 |
Correct |
92 ms |
14284 KB |
Output is correct |
45 |
Correct |
97 ms |
14272 KB |
Output is correct |
46 |
Correct |
64 ms |
7816 KB |
Output is correct |
47 |
Correct |
72 ms |
7616 KB |
Output is correct |
48 |
Correct |
72 ms |
7612 KB |
Output is correct |
49 |
Correct |
156 ms |
15024 KB |
Output is correct |
50 |
Correct |
81 ms |
14008 KB |
Output is correct |
51 |
Correct |
70 ms |
10680 KB |
Output is correct |
52 |
Correct |
97 ms |
14776 KB |
Output is correct |
53 |
Correct |
88 ms |
14524 KB |
Output is correct |
54 |
Correct |
107 ms |
14724 KB |
Output is correct |
55 |
Correct |
142 ms |
15032 KB |
Output is correct |