#include <bits/stdc++.h>
#define maxn 500000
using namespace std;
int seg[4*maxn];
map<int,int> pos;
set<int> s;
int n,x;
int t[maxn];
void clear(int id,int l,int r) {
seg[id]=0;
if(l==r) return;
int mid=(l+r)/2;
clear(id*2+1,l,mid);
clear(id*2+2,mid+1,r);
}
int query(int id,int l,int r,int x,int y) {
if(x<=l && r<=y) return seg[id];
if(y<l || r<x) return 0;
int mid=(l+r)/2;
return max(query(id*2+1,l,mid,x,y),query(id*2+2,mid+1,r,x,y));
}
void update(int id,int l,int r,int p,int v) {
seg[id]=max(seg[id],v);
if(l==r) return;
int mid=(l+r)/2;
if(p<=mid) update(id*2+1,l,mid,p,v);
else update(id*2+2,mid+1,r,p,v);
}
int pref[maxn];
int suf[maxn];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>x;
for(int i=1;i<=n;i++) {
cin>>t[i];
s.insert(t[i]);
s.insert(t[i]-x);
}
int id=0;
for(auto v:s) {
pos[v]=id++;
}
clear(0,0,maxn);
for(int i=1;i<=n;i++) {
pref[i]=1+query(0,0,maxn,0,pos[t[i]]-1);
update(0,0,maxn,pos[t[i]],pref[i]);
}
clear(0,0,maxn);
for(int i=n;i>=1;i--) {
suf[i]=1+query(0,0,maxn,pos[t[i]]+1,maxn);
update(0,0,maxn,pos[t[i]],suf[i]);
}
clear(0,0,maxn);
int ans=0;
for(int i=1;i<=n;i++) {
ans=max(ans,suf[i]+query(0,0,maxn,0,pos[t[i]]-1));
update(0,0,maxn,pos[t[i]-x],pref[i]);
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10708 KB |
Output is correct |
2 |
Correct |
4 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
10708 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
4 ms |
10588 KB |
Output is correct |
7 |
Correct |
4 ms |
10588 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
4 ms |
10704 KB |
Output is correct |
10 |
Correct |
3 ms |
10584 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10708 KB |
Output is correct |
2 |
Correct |
4 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
10708 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
4 ms |
10588 KB |
Output is correct |
7 |
Correct |
4 ms |
10588 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
4 ms |
10704 KB |
Output is correct |
10 |
Correct |
3 ms |
10584 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
4 ms |
10588 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
10588 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
4 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10708 KB |
Output is correct |
2 |
Correct |
4 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
10708 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
4 ms |
10588 KB |
Output is correct |
7 |
Correct |
4 ms |
10588 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
4 ms |
10704 KB |
Output is correct |
10 |
Correct |
3 ms |
10584 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
4 ms |
10588 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
10588 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
4 ms |
10588 KB |
Output is correct |
19 |
Correct |
6 ms |
10844 KB |
Output is correct |
20 |
Correct |
6 ms |
10844 KB |
Output is correct |
21 |
Correct |
6 ms |
10844 KB |
Output is correct |
22 |
Correct |
5 ms |
10588 KB |
Output is correct |
23 |
Correct |
5 ms |
10584 KB |
Output is correct |
24 |
Correct |
4 ms |
10824 KB |
Output is correct |
25 |
Correct |
5 ms |
10584 KB |
Output is correct |
26 |
Correct |
5 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
503 ms |
31316 KB |
Output is correct |
2 |
Correct |
501 ms |
31492 KB |
Output is correct |
3 |
Correct |
485 ms |
31316 KB |
Output is correct |
4 |
Correct |
464 ms |
31316 KB |
Output is correct |
5 |
Correct |
199 ms |
21328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
20576 KB |
Output is correct |
2 |
Correct |
121 ms |
20560 KB |
Output is correct |
3 |
Correct |
115 ms |
20596 KB |
Output is correct |
4 |
Correct |
57 ms |
15704 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
66 ms |
15676 KB |
Output is correct |
7 |
Correct |
108 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
30548 KB |
Output is correct |
2 |
Correct |
292 ms |
30544 KB |
Output is correct |
3 |
Correct |
616 ms |
50232 KB |
Output is correct |
4 |
Correct |
236 ms |
30800 KB |
Output is correct |
5 |
Correct |
179 ms |
30036 KB |
Output is correct |
6 |
Correct |
324 ms |
47704 KB |
Output is correct |
7 |
Correct |
366 ms |
48124 KB |
Output is correct |
8 |
Correct |
208 ms |
30544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10708 KB |
Output is correct |
2 |
Correct |
4 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
10708 KB |
Output is correct |
4 |
Correct |
3 ms |
10588 KB |
Output is correct |
5 |
Correct |
4 ms |
10588 KB |
Output is correct |
6 |
Correct |
4 ms |
10588 KB |
Output is correct |
7 |
Correct |
4 ms |
10588 KB |
Output is correct |
8 |
Correct |
4 ms |
10588 KB |
Output is correct |
9 |
Correct |
4 ms |
10704 KB |
Output is correct |
10 |
Correct |
3 ms |
10584 KB |
Output is correct |
11 |
Correct |
4 ms |
10588 KB |
Output is correct |
12 |
Correct |
4 ms |
10588 KB |
Output is correct |
13 |
Correct |
4 ms |
10588 KB |
Output is correct |
14 |
Correct |
4 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
10588 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
4 ms |
10588 KB |
Output is correct |
19 |
Correct |
6 ms |
10844 KB |
Output is correct |
20 |
Correct |
6 ms |
10844 KB |
Output is correct |
21 |
Correct |
6 ms |
10844 KB |
Output is correct |
22 |
Correct |
5 ms |
10588 KB |
Output is correct |
23 |
Correct |
5 ms |
10584 KB |
Output is correct |
24 |
Correct |
4 ms |
10824 KB |
Output is correct |
25 |
Correct |
5 ms |
10584 KB |
Output is correct |
26 |
Correct |
5 ms |
10588 KB |
Output is correct |
27 |
Correct |
503 ms |
31316 KB |
Output is correct |
28 |
Correct |
501 ms |
31492 KB |
Output is correct |
29 |
Correct |
485 ms |
31316 KB |
Output is correct |
30 |
Correct |
464 ms |
31316 KB |
Output is correct |
31 |
Correct |
199 ms |
21328 KB |
Output is correct |
32 |
Correct |
129 ms |
20576 KB |
Output is correct |
33 |
Correct |
121 ms |
20560 KB |
Output is correct |
34 |
Correct |
115 ms |
20596 KB |
Output is correct |
35 |
Correct |
57 ms |
15704 KB |
Output is correct |
36 |
Correct |
4 ms |
10588 KB |
Output is correct |
37 |
Correct |
66 ms |
15676 KB |
Output is correct |
38 |
Correct |
108 ms |
19036 KB |
Output is correct |
39 |
Correct |
294 ms |
30548 KB |
Output is correct |
40 |
Correct |
292 ms |
30544 KB |
Output is correct |
41 |
Correct |
616 ms |
50232 KB |
Output is correct |
42 |
Correct |
236 ms |
30800 KB |
Output is correct |
43 |
Correct |
179 ms |
30036 KB |
Output is correct |
44 |
Correct |
324 ms |
47704 KB |
Output is correct |
45 |
Correct |
366 ms |
48124 KB |
Output is correct |
46 |
Correct |
208 ms |
30544 KB |
Output is correct |
47 |
Correct |
248 ms |
30452 KB |
Output is correct |
48 |
Correct |
258 ms |
30400 KB |
Output is correct |
49 |
Correct |
592 ms |
50260 KB |
Output is correct |
50 |
Correct |
249 ms |
30804 KB |
Output is correct |
51 |
Correct |
212 ms |
25680 KB |
Output is correct |
52 |
Correct |
301 ms |
30800 KB |
Output is correct |
53 |
Correct |
331 ms |
49488 KB |
Output is correct |
54 |
Correct |
397 ms |
50296 KB |
Output is correct |
55 |
Correct |
431 ms |
44204 KB |
Output is correct |