#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
#define N 200200
int n , x , l , r , mid , p , rt , a[N] , b[N] , f[N] , g[N];
int bs(int x){
l = 1 , r = n;
while (l <= r){
mid = (l + r) >> 1;
if (b[mid] <= x) p = mid , r = mid - 1; else l = mid + 1;
}
return p;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> x;
for (int i = 1 ; i <= n ; i ++) cin >> a[i] , b[i] = 2e9;
for (int i = 1 ; i <= n ; i ++){
p = lower_bound(b , b + n + 1 , a[i]) - b;
rt = max(rt,p) , b[p] = a[i];
}
if (n <= 1000){
for (int i = 1 ; i <= n ; i ++){
f[i] = 1;
for (int j = 1 ; j < i ; j ++) if (a[j] < a[i]) f[i] = max(f[i],f[j] + 1);
}
for (int i = n ; i ; i --){
g[i] = 1;
for (int j = i + 1 ; j <= n ; j ++) if (a[i] < a[j]) g[i] = max(g[i],g[j] + 1);
}
for (int i = 1 ; i <= n ; i ++){
for (int j = 1 ; j <= n ; j ++){
if (j < f[i]) b[j] = 0;
if (j == f[i]) b[j] = a[i];
if (j > f[i]) b[j] = 2e9;
}
for (int j = i + 1 ; j <= n ; j ++){
p = lower_bound(b , b + n + 1 , a[j] + x) - b;
rt = max(rt,p) , b[p] = a[j] + x;
}
for (int j = 1 ; j <= n ; j ++){
if (j < f[i]) b[j] = 0;
if (j == f[i]) b[j] = a[i];
if (j > f[i]) b[j] = 2e9;
}
for (int j = i + 1 ; j <= n ; j ++){
p = lower_bound(b , b + n + 1 , a[j] - x) - b;
rt = max(rt,p) , b[p] = a[j] - x;
}
}
for (int i = n ; i ; i --){
for (int j = i - 1 ; j ; j --){
if (j < g[i]) b[j] = 4e9;
if (j == g[i]) b[j] = a[i];
if (j > g[i]) b[j] = 0;
}
for (int j = i - 1 ; j ; j --){
p = bs(a[i] + x);
rt = max(rt , p) , a[p] = rt;
}
for (int j = i - 1 ; j ; j --){
if (j < g[i]) b[j] = 4e9;
if (j == g[i]) b[j] = a[i];
if (j > g[i]) b[j] = 0;
}
for (int j = i - 1 ; j ; j --){
p = bs(a[i] - x);
rt = max(rt , p) , a[p] = rt;
}
}
}
cout << rt;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5464 KB |
Output is correct |
2 |
Correct |
29 ms |
5464 KB |
Output is correct |
3 |
Correct |
24 ms |
5468 KB |
Output is correct |
4 |
Correct |
24 ms |
5444 KB |
Output is correct |
5 |
Correct |
17 ms |
4756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1628 KB |
Output is correct |
2 |
Correct |
6 ms |
1652 KB |
Output is correct |
3 |
Correct |
6 ms |
1624 KB |
Output is correct |
4 |
Incorrect |
5 ms |
1372 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
3012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |