#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 4e5 + 7;
int n , x , a[maxn] , b[maxn];
struct Fenwick
{
int bit[maxn];
void update(int pos,int val)
{
for(;pos < maxn;pos += pos & -pos)bit[pos] = max(bit[pos],val);
}
int get(int pos)
{
int res = 0;
for(;pos > 0;pos -= pos & -pos)res = max(res,bit[pos]);
return res;
}
};
Fenwick sta , stb;
void compress()
{
vector <int> order;
for(int i = 1; i <= n; i++)
{
order.push_back(a[i]);
order.push_back(a[i] - x);
}
sort(order.begin() , order.end());
order.erase(unique(order.begin(),order.end()),order.end());
for(int i = 1; i <= n; i++)
{
b[i] = lower_bound(order.begin() , order.end() , a[i] - x) - order.begin() + 1;
a[i] = lower_bound(order.begin() , order.end() , a[i]) - order.begin() + 1;
}
}
void solve()
{
cin >> n >> x;
for(int i = 1; i <= n; i++) cin >> a[i];
compress();
//for(int i = 1; i <= n; i++) cout << a[i] << ' '; cout << '\n';
//for(int i = 1; i <= n; i++) cout << b[i] << ' '; cout << '\n';
int ans = 0;
for(int i = 1; i <= n; i++)
{
// b[i] = a[i] - x
int geta1 = sta.get(b[i] - 1); // lay nhung thg a[i] - x
ans = max(ans , geta1 + 1);
int getb2 = stb.get(a[i] - 1);// lay a[i]
int geta2 = sta.get(a[i] - 1); // lay nhung thg a[i] - x
ans = max(ans , max(getb2 , geta2) + 1);
//cout << geta1 << ' ' << geta2 << ' ' << getb2 << '\n';
stb.update(a[i] , max(getb2 , geta2) + 1);
sta.update(b[i] , geta1 + 1);
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
468 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 |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
5576 KB |
Output is correct |
2 |
Correct |
89 ms |
5580 KB |
Output is correct |
3 |
Correct |
89 ms |
5572 KB |
Output is correct |
4 |
Correct |
89 ms |
5648 KB |
Output is correct |
5 |
Correct |
41 ms |
4808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2384 KB |
Output is correct |
2 |
Correct |
21 ms |
2128 KB |
Output is correct |
3 |
Correct |
21 ms |
2132 KB |
Output is correct |
4 |
Correct |
11 ms |
1664 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1604 KB |
Output is correct |
7 |
Correct |
18 ms |
2108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
3024 KB |
Output is correct |
2 |
Correct |
49 ms |
3000 KB |
Output is correct |
3 |
Correct |
121 ms |
5640 KB |
Output is correct |
4 |
Correct |
47 ms |
4804 KB |
Output is correct |
5 |
Correct |
28 ms |
2752 KB |
Output is correct |
6 |
Correct |
49 ms |
4808 KB |
Output is correct |
7 |
Correct |
50 ms |
5368 KB |
Output is correct |
8 |
Correct |
41 ms |
3032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
468 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 |
476 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
91 ms |
5576 KB |
Output is correct |
28 |
Correct |
89 ms |
5580 KB |
Output is correct |
29 |
Correct |
89 ms |
5572 KB |
Output is correct |
30 |
Correct |
89 ms |
5648 KB |
Output is correct |
31 |
Correct |
41 ms |
4808 KB |
Output is correct |
32 |
Correct |
24 ms |
2384 KB |
Output is correct |
33 |
Correct |
21 ms |
2128 KB |
Output is correct |
34 |
Correct |
21 ms |
2132 KB |
Output is correct |
35 |
Correct |
11 ms |
1664 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
10 ms |
1604 KB |
Output is correct |
38 |
Correct |
18 ms |
2108 KB |
Output is correct |
39 |
Correct |
48 ms |
3024 KB |
Output is correct |
40 |
Correct |
49 ms |
3000 KB |
Output is correct |
41 |
Correct |
121 ms |
5640 KB |
Output is correct |
42 |
Correct |
47 ms |
4804 KB |
Output is correct |
43 |
Correct |
28 ms |
2752 KB |
Output is correct |
44 |
Correct |
49 ms |
4808 KB |
Output is correct |
45 |
Correct |
50 ms |
5368 KB |
Output is correct |
46 |
Correct |
41 ms |
3032 KB |
Output is correct |
47 |
Correct |
46 ms |
3732 KB |
Output is correct |
48 |
Correct |
47 ms |
3752 KB |
Output is correct |
49 |
Correct |
99 ms |
7336 KB |
Output is correct |
50 |
Correct |
44 ms |
4884 KB |
Output is correct |
51 |
Correct |
43 ms |
4052 KB |
Output is correct |
52 |
Correct |
52 ms |
5040 KB |
Output is correct |
53 |
Correct |
53 ms |
4888 KB |
Output is correct |
54 |
Correct |
56 ms |
5692 KB |
Output is correct |
55 |
Correct |
85 ms |
6568 KB |
Output is correct |