#include<bits/stdc++.h>
using namespace std;
struct {
map<int,int>mp;
int query(int pos){
int ans=0;
while(pos)
ans=max(ans,mp[pos]),
pos-=pos&-pos;
return ans;
}
void upd(long long pos,int x){
while(pos<=2e9)
mp[pos]=max(mp[pos],x),
pos+=pos&-pos;
}
void reset(){
mp.clear();
}
} BIT;
int goleft[200100], goright[200100], vl[200100];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,x;
cin>>n>>x;
for(int i=1;i<=n;i++){ cin>>vl[i];
goleft[i]=BIT.query(vl[i]-1)+1;
BIT.upd(vl[i],goleft[i]);
}
BIT.reset();
for(int i=n;i;i--){
goright[i]=BIT.query(1e9-vl[i])+1;
BIT.upd(1e9-vl[i]+1,goright[i]);
}
int ans=0;
BIT.reset();
for(int i=1;i<=n;i++){
ans=max(ans,goright[i]+BIT.query(vl[i]+x-1));
BIT.upd(vl[i],goleft[i]);
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
12 ms |
3380 KB |
Output is correct |
20 |
Correct |
12 ms |
3460 KB |
Output is correct |
21 |
Correct |
12 ms |
3392 KB |
Output is correct |
22 |
Correct |
11 ms |
3420 KB |
Output is correct |
23 |
Correct |
5 ms |
2908 KB |
Output is correct |
24 |
Correct |
9 ms |
2908 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2094 ms |
119004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
961 ms |
36260 KB |
Output is correct |
2 |
Correct |
988 ms |
36180 KB |
Output is correct |
3 |
Correct |
903 ms |
36420 KB |
Output is correct |
4 |
Correct |
313 ms |
20520 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
171 ms |
4952 KB |
Output is correct |
7 |
Correct |
541 ms |
26192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2045 ms |
65548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
12 ms |
3380 KB |
Output is correct |
20 |
Correct |
12 ms |
3460 KB |
Output is correct |
21 |
Correct |
12 ms |
3392 KB |
Output is correct |
22 |
Correct |
11 ms |
3420 KB |
Output is correct |
23 |
Correct |
5 ms |
2908 KB |
Output is correct |
24 |
Correct |
9 ms |
2908 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
27 |
Execution timed out |
2094 ms |
119004 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |