#include <bits/stdc++.h>
using namespace std;
constexpr int N = (int)7e5;
int t[3][N];
void upd(int r,int d,int v){
for(int i = r; i < N; i |= i+1)
t[v][i] = max(t[v][i],d);
return;
}
int get(int r,int v){
int s = 0;
for(int i = r; i >= 0; i &= i+1,i--){
s = max(s,t[v][i]);
}
return s;
}
void solve(){
int n,x;
cin >> n >> x;
int a[n+1];
set<int> st;
for(int i = 1; i <= n; i++){
cin >> a[i];
st.insert(a[i]-x);
st.insert(a[i]);
}
vector<int> v(st.begin(),st.end());
map<int,int> tr;
for(auto& x : v){
tr[x] = tr.size();
}
int ans = 0;
for(int i = 1; i <= n; i++){
int c;
c = get(tr[a[i]]-1,2);
ans = max(ans,c+1);
upd(tr[a[i]],c+1,2);
c = get(tr[a[i]]-1,1);
ans = max(ans,c+1);
upd(tr[a[i]],c+1,2);
c = get(tr[a[i]-x]-1,1);
ans = max(ans,c+1);
upd(tr[a[i]-x],c+1,1);
c = get(tr[a[i]-x]-1,0);
ans = max(ans,c+1);
upd(tr[a[i]-x],c+1,1);
c = get(tr[a[i]]-1,0);
ans = max(ans,c+1);
upd(tr[a[i]],c+1,0);
}
cout << ans << "\n";
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int tests = 1;
for(int test = 1; test <= tests; test++){
solve();
}
return 0;
}
/**
8 10
7 3 5 12 2 7 3 4
[ ]
1 2 2
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
452 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
452 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
407 ms |
24932 KB |
Output is correct |
2 |
Correct |
413 ms |
24908 KB |
Output is correct |
3 |
Correct |
411 ms |
24944 KB |
Output is correct |
4 |
Correct |
417 ms |
24960 KB |
Output is correct |
5 |
Correct |
175 ms |
13260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
12032 KB |
Output is correct |
2 |
Correct |
118 ms |
11956 KB |
Output is correct |
3 |
Correct |
101 ms |
11972 KB |
Output is correct |
4 |
Correct |
46 ms |
6348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
53 ms |
6388 KB |
Output is correct |
7 |
Correct |
82 ms |
10144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
22496 KB |
Output is correct |
2 |
Correct |
252 ms |
22476 KB |
Output is correct |
3 |
Correct |
683 ms |
44492 KB |
Output is correct |
4 |
Correct |
261 ms |
22988 KB |
Output is correct |
5 |
Correct |
179 ms |
22040 KB |
Output is correct |
6 |
Correct |
352 ms |
41732 KB |
Output is correct |
7 |
Correct |
353 ms |
42360 KB |
Output is correct |
8 |
Correct |
211 ms |
22476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
452 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
596 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
580 KB |
Output is correct |
27 |
Correct |
407 ms |
24932 KB |
Output is correct |
28 |
Correct |
413 ms |
24908 KB |
Output is correct |
29 |
Correct |
411 ms |
24944 KB |
Output is correct |
30 |
Correct |
417 ms |
24960 KB |
Output is correct |
31 |
Correct |
175 ms |
13260 KB |
Output is correct |
32 |
Correct |
99 ms |
12032 KB |
Output is correct |
33 |
Correct |
118 ms |
11956 KB |
Output is correct |
34 |
Correct |
101 ms |
11972 KB |
Output is correct |
35 |
Correct |
46 ms |
6348 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
53 ms |
6388 KB |
Output is correct |
38 |
Correct |
82 ms |
10144 KB |
Output is correct |
39 |
Correct |
264 ms |
22496 KB |
Output is correct |
40 |
Correct |
252 ms |
22476 KB |
Output is correct |
41 |
Correct |
683 ms |
44492 KB |
Output is correct |
42 |
Correct |
261 ms |
22988 KB |
Output is correct |
43 |
Correct |
179 ms |
22040 KB |
Output is correct |
44 |
Correct |
352 ms |
41732 KB |
Output is correct |
45 |
Correct |
353 ms |
42360 KB |
Output is correct |
46 |
Correct |
211 ms |
22476 KB |
Output is correct |
47 |
Correct |
225 ms |
23660 KB |
Output is correct |
48 |
Correct |
242 ms |
23624 KB |
Output is correct |
49 |
Correct |
587 ms |
46892 KB |
Output is correct |
50 |
Correct |
254 ms |
24140 KB |
Output is correct |
51 |
Correct |
195 ms |
17684 KB |
Output is correct |
52 |
Correct |
291 ms |
24396 KB |
Output is correct |
53 |
Correct |
372 ms |
43820 KB |
Output is correct |
54 |
Correct |
384 ms |
44620 KB |
Output is correct |
55 |
Correct |
410 ms |
39724 KB |
Output is correct |