#include <bits/stdc++.h>
using namespace std;
const int mx=1e6+5;
vector<int> tw(mx,1e9);
int query(int i,int l,int r,int v){
if(l==r) return l;
if(tw[i*2+1]<v) return query(i*2+1,(l+r)/2+1,r,v);
return query(i*2,l,(r+l)/2,v);
}
void update(int i,int l,int r,int target,int v){
if(target<l||r<target) return;
if(l==r) tw[i]=min(tw[i],v);
else{
update(i*2,l,(r+l)/2,target,v);
update(i*2+1,(r+l)/2+1,r,target,v);
tw[i]=min(tw[i*2],tw[i*2+1]);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n,x;
cin>>n>>x;
vector<int> a(n);
for(int&x:a)cin>>x;
vector<int> on(n+1,2e9+1);
on[0]=0;
update(1,0,n,0,0);
int answer=0;
for(int i=0;i<n;i++){
int l=0,r=n+1;
while(r-l!=1){int md=(r+l)/2; if(on[md]<a[i]) l=md;else r=md;}
int one=l+1;
l=0,r=n+1;
while(r-l!=1){int md=(r+l)/2; if(on[md]-x<a[i]) l=md; else r=md;}
int two=l+1;
l=query(1,0,n,a[i]);
on[one]=min(a[i],on[one]);
answer=max({answer,l+1,two,one});
update(1,0,n,max({l+1,two,one}),a[i]);
}
cout<<answer;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
3 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
3 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
3 ms |
4180 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
3 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
3 ms |
4180 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
3 ms |
4180 KB |
Output is correct |
20 |
Correct |
3 ms |
4252 KB |
Output is correct |
21 |
Correct |
3 ms |
4180 KB |
Output is correct |
22 |
Correct |
3 ms |
4256 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4256 KB |
Output is correct |
25 |
Correct |
3 ms |
4252 KB |
Output is correct |
26 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
7696 KB |
Output is correct |
2 |
Correct |
102 ms |
7684 KB |
Output is correct |
3 |
Correct |
112 ms |
7720 KB |
Output is correct |
4 |
Correct |
110 ms |
7728 KB |
Output is correct |
5 |
Correct |
103 ms |
6916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
5076 KB |
Output is correct |
2 |
Correct |
27 ms |
5076 KB |
Output is correct |
3 |
Correct |
25 ms |
5052 KB |
Output is correct |
4 |
Correct |
23 ms |
4908 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
26 ms |
4820 KB |
Output is correct |
7 |
Correct |
25 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
5980 KB |
Output is correct |
2 |
Correct |
48 ms |
5908 KB |
Output is correct |
3 |
Correct |
97 ms |
7728 KB |
Output is correct |
4 |
Correct |
128 ms |
6952 KB |
Output is correct |
5 |
Correct |
58 ms |
5596 KB |
Output is correct |
6 |
Correct |
86 ms |
6912 KB |
Output is correct |
7 |
Correct |
95 ms |
7580 KB |
Output is correct |
8 |
Correct |
48 ms |
5988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4180 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
3 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4180 KB |
Output is correct |
12 |
Correct |
3 ms |
4180 KB |
Output is correct |
13 |
Correct |
3 ms |
4180 KB |
Output is correct |
14 |
Correct |
3 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
3 ms |
4180 KB |
Output is correct |
20 |
Correct |
3 ms |
4252 KB |
Output is correct |
21 |
Correct |
3 ms |
4180 KB |
Output is correct |
22 |
Correct |
3 ms |
4256 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4256 KB |
Output is correct |
25 |
Correct |
3 ms |
4252 KB |
Output is correct |
26 |
Correct |
3 ms |
4308 KB |
Output is correct |
27 |
Correct |
111 ms |
7696 KB |
Output is correct |
28 |
Correct |
102 ms |
7684 KB |
Output is correct |
29 |
Correct |
112 ms |
7720 KB |
Output is correct |
30 |
Correct |
110 ms |
7728 KB |
Output is correct |
31 |
Correct |
103 ms |
6916 KB |
Output is correct |
32 |
Correct |
25 ms |
5076 KB |
Output is correct |
33 |
Correct |
27 ms |
5076 KB |
Output is correct |
34 |
Correct |
25 ms |
5052 KB |
Output is correct |
35 |
Correct |
23 ms |
4908 KB |
Output is correct |
36 |
Correct |
3 ms |
4180 KB |
Output is correct |
37 |
Correct |
26 ms |
4820 KB |
Output is correct |
38 |
Correct |
25 ms |
5068 KB |
Output is correct |
39 |
Correct |
55 ms |
5980 KB |
Output is correct |
40 |
Correct |
48 ms |
5908 KB |
Output is correct |
41 |
Correct |
97 ms |
7728 KB |
Output is correct |
42 |
Correct |
128 ms |
6952 KB |
Output is correct |
43 |
Correct |
58 ms |
5596 KB |
Output is correct |
44 |
Correct |
86 ms |
6912 KB |
Output is correct |
45 |
Correct |
95 ms |
7580 KB |
Output is correct |
46 |
Correct |
48 ms |
5988 KB |
Output is correct |
47 |
Correct |
53 ms |
5984 KB |
Output is correct |
48 |
Correct |
52 ms |
5964 KB |
Output is correct |
49 |
Correct |
108 ms |
7716 KB |
Output is correct |
50 |
Correct |
130 ms |
6960 KB |
Output is correct |
51 |
Correct |
98 ms |
6276 KB |
Output is correct |
52 |
Correct |
113 ms |
7044 KB |
Output is correct |
53 |
Correct |
112 ms |
7056 KB |
Output is correct |
54 |
Correct |
101 ms |
7756 KB |
Output is correct |
55 |
Correct |
102 ms |
7704 KB |
Output is correct |