#include<bits/stdc++.h>
using namespace std;
#include<fstream>
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
typedef unsigned long long ull;
#define pii pair<int, int>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const ll mod= 1e9 + 7;
const int mxk = 1e3, sq = 750, mxn = 2e5;
const ll inf = -1e18;
int n, x;
int d[mxn + 1][4];
struct BIT{
int bit[mxn * 3 + 1];
void upd(int p, int v){
while(p <= mxn * 3){
bit[p] = max(bit[p], v);
p += p & (-p);
}
}
int get(int p){
int ans = 0;
while(p){
ans = max(ans, bit[p]);
p -= p & (-p);
}
return(ans);
}
};
BIT bit[4];
vt<ll>b;
ll a[mxn + 1];
int find(ll x){
return(lower_bound(b.begin(), b.end(), x) - b.begin() + 1);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> x;
for(int i = 1; i <= n; i++){
cin >> a[i]; b.pb(a[i] + x); b.pb(a[i] - x); b.pb(a[i]);
}
int ans = 0;
sort(b.begin(), b.end());
for(int i = 1; i <= n; i++){
d[i][0] = bit[0].get(find(a[i]) - 1) + 1; d[i][1] = max(bit[1].get(find(a[i] + x) - 1), bit[0].get(find(a[i] + x) - 1)) + 1;
d[i][2] = max(bit[2].get(find(a[i] - x) - 1), bit[0].get(find(a[i] - x) - 1)) + 1;
d[i][3] = max({bit[2].get(find(a[i]) - 1), bit[1].get(find(a[i]) - 1), bit[3].get(find(a[i]) - 1)}) + 1;
bit[0].upd(find(a[i]), d[i][0]); bit[1].upd(find(a[i] + x), d[i][1]); bit[2].upd(find(a[i] - x), d[i][2]);
bit[3].upd(find(a[i]), d[i][3]);
ans = max({ans, d[i][0], d[i][1], d[i][2], d[i][3]});
}
cout << ans;
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
19204 KB |
Output is correct |
2 |
Correct |
326 ms |
21152 KB |
Output is correct |
3 |
Correct |
308 ms |
21148 KB |
Output is correct |
4 |
Correct |
326 ms |
21076 KB |
Output is correct |
5 |
Correct |
127 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
5292 KB |
Output is correct |
2 |
Correct |
60 ms |
5248 KB |
Output is correct |
3 |
Correct |
63 ms |
5256 KB |
Output is correct |
4 |
Correct |
33 ms |
4336 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
39 ms |
5224 KB |
Output is correct |
7 |
Correct |
54 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
6760 KB |
Output is correct |
2 |
Correct |
160 ms |
6752 KB |
Output is correct |
3 |
Correct |
360 ms |
13796 KB |
Output is correct |
4 |
Correct |
149 ms |
12844 KB |
Output is correct |
5 |
Correct |
87 ms |
7372 KB |
Output is correct |
6 |
Correct |
154 ms |
13624 KB |
Output is correct |
7 |
Correct |
158 ms |
14216 KB |
Output is correct |
8 |
Correct |
115 ms |
7700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
347 ms |
19204 KB |
Output is correct |
28 |
Correct |
326 ms |
21152 KB |
Output is correct |
29 |
Correct |
308 ms |
21148 KB |
Output is correct |
30 |
Correct |
326 ms |
21076 KB |
Output is correct |
31 |
Correct |
127 ms |
15964 KB |
Output is correct |
32 |
Correct |
62 ms |
5292 KB |
Output is correct |
33 |
Correct |
60 ms |
5248 KB |
Output is correct |
34 |
Correct |
63 ms |
5256 KB |
Output is correct |
35 |
Correct |
33 ms |
4336 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
39 ms |
5224 KB |
Output is correct |
38 |
Correct |
54 ms |
5248 KB |
Output is correct |
39 |
Correct |
143 ms |
6760 KB |
Output is correct |
40 |
Correct |
160 ms |
6752 KB |
Output is correct |
41 |
Correct |
360 ms |
13796 KB |
Output is correct |
42 |
Correct |
149 ms |
12844 KB |
Output is correct |
43 |
Correct |
87 ms |
7372 KB |
Output is correct |
44 |
Correct |
154 ms |
13624 KB |
Output is correct |
45 |
Correct |
158 ms |
14216 KB |
Output is correct |
46 |
Correct |
115 ms |
7700 KB |
Output is correct |
47 |
Correct |
138 ms |
10832 KB |
Output is correct |
48 |
Correct |
150 ms |
10840 KB |
Output is correct |
49 |
Correct |
316 ms |
21064 KB |
Output is correct |
50 |
Correct |
141 ms |
15920 KB |
Output is correct |
51 |
Correct |
127 ms |
12672 KB |
Output is correct |
52 |
Correct |
192 ms |
20480 KB |
Output is correct |
53 |
Correct |
161 ms |
14252 KB |
Output is correct |
54 |
Correct |
170 ms |
14908 KB |
Output is correct |
55 |
Correct |
229 ms |
21164 KB |
Output is correct |