#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define FORR1(x) for(int i = 0; i < (x); i++)
#define FORR2(j,x) for(int (j) = 0; (j) < (x); (j)++)
#define f first
#define s second
typedef vt<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
map<int,vi> mp;
map<int,int> dic;
int pp[10005];
int sz[10005];
int cst[10005];
int ans[10005][103];
int find(int x){
return (x==pp[x] ? x : pp[x] = find(pp[x]));
}
void join(int a, int b){
if(find(a)==find(b))return;
int u = find(a), v = find(b);
if(sz[u]>sz[v])swap(u,v);
pp[u] = v;
sz[v]+=sz[u];
}
int arr[200005];
int in2[200005];
int out2[200005];
int in1[200005];
int out1[200005];
void solve(){
int n, x;
cin>>n>>x;
FORR1(n)cin>>arr[i];
set<int,greater<>> st2;
for(int i = n-1; i>=0; i--){
auto it = st2.lower_bound(arr[i]);
if(it == st2.end()){
in2[i] = arr[i];
out2[i] = -1;
st2.insert(arr[i]);
}else{
in2[i] = arr[i];
out2[i] = *it;
st2.erase(it);
st2.insert(arr[i]);
}
}
set<int> st1;
FORR1(n){
auto it = st1.lower_bound(arr[i]);
if(it == st1.end()){
in1[i] = arr[i];
out1[i] = -1;
st1.insert(arr[i]);
}else{
in1[i] = arr[i];
out1[i] = *it;
st1.erase(it);
st1.insert(arr[i]);
}
}
int a = st1.size(), b = st2.size();
vi cal1(a), cal2(b);
FORR1(a)cal1[i] = -1;
int att = 0;
for(auto & e: st2){
cal2[att] = e;
att++;
}
int ans = b;
int at1 = -1, at2 = b-1;
FORR1(n){
int l = 0, r = a;
while(l!=r){
int mid = (l+r)>>1;
if(cal1[mid]==-1||(out1[i]!=-1&&out1[i]<cal1[mid])){
r = mid;
}else if(cal1[mid]==out1[i]){
l = mid;
r = mid;
}else{
l = mid+1;
}
}
cal1[l] = in1[i];
l = 0; r = b;
while(l!=r){
int mid = (l+r)>>1;
if(cal2[mid]>in2[i]){
l = mid+1;
}else if(cal2[mid]<in2[i]){
r = mid;
}else{
l = r = mid;
}
}
cal2[l] = out2[i];
if(cal2[at2]==-1){
at2--;
}
if(at1==-1){
if(cal1[0]-cal2[at2]<x){
at1 = 0;
}
}else if(at2!=-1){
if(cal1[at1]-cal2[at2]<x){
if(at1!=a-1&&cal1[at1+1]!=-1&&cal1[at1+1]-cal2[at2]<x){
at1++;
}
}else{
at2--;
if(at2!=-1&&at1!=a-1&&cal1[at1+1]!=-1&&cal1[at1+1]-cal2[at2]<x){
at1++;
}
}
}
ans = max(ans, at1+at2+2);
/*if(at1+at2+2==6){
cout<<i<<'\n';
cout<<at1<<' '<<at2<<'\n';
}*/
}
ans = max(ans,(int)st1.size());
cout<<ans<<'\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
4744 KB |
Output is correct |
2 |
Correct |
108 ms |
4628 KB |
Output is correct |
3 |
Correct |
111 ms |
4704 KB |
Output is correct |
4 |
Correct |
109 ms |
4680 KB |
Output is correct |
5 |
Correct |
157 ms |
14756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1736 KB |
Output is correct |
2 |
Correct |
28 ms |
1648 KB |
Output is correct |
3 |
Correct |
29 ms |
1740 KB |
Output is correct |
4 |
Correct |
33 ms |
4028 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
39 ms |
4108 KB |
Output is correct |
7 |
Correct |
21 ms |
1652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
2672 KB |
Output is correct |
2 |
Correct |
54 ms |
2736 KB |
Output is correct |
3 |
Correct |
129 ms |
4628 KB |
Output is correct |
4 |
Correct |
167 ms |
14676 KB |
Output is correct |
5 |
Correct |
74 ms |
7692 KB |
Output is correct |
6 |
Correct |
111 ms |
14108 KB |
Output is correct |
7 |
Correct |
131 ms |
14024 KB |
Output is correct |
8 |
Correct |
45 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
110 ms |
4744 KB |
Output is correct |
28 |
Correct |
108 ms |
4628 KB |
Output is correct |
29 |
Correct |
111 ms |
4704 KB |
Output is correct |
30 |
Correct |
109 ms |
4680 KB |
Output is correct |
31 |
Correct |
157 ms |
14756 KB |
Output is correct |
32 |
Correct |
25 ms |
1736 KB |
Output is correct |
33 |
Correct |
28 ms |
1648 KB |
Output is correct |
34 |
Correct |
29 ms |
1740 KB |
Output is correct |
35 |
Correct |
33 ms |
4028 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
39 ms |
4108 KB |
Output is correct |
38 |
Correct |
21 ms |
1652 KB |
Output is correct |
39 |
Correct |
54 ms |
2672 KB |
Output is correct |
40 |
Correct |
54 ms |
2736 KB |
Output is correct |
41 |
Correct |
129 ms |
4628 KB |
Output is correct |
42 |
Correct |
167 ms |
14676 KB |
Output is correct |
43 |
Correct |
74 ms |
7692 KB |
Output is correct |
44 |
Correct |
111 ms |
14108 KB |
Output is correct |
45 |
Correct |
131 ms |
14024 KB |
Output is correct |
46 |
Correct |
45 ms |
2636 KB |
Output is correct |
47 |
Correct |
57 ms |
3264 KB |
Output is correct |
48 |
Correct |
54 ms |
3264 KB |
Output is correct |
49 |
Correct |
124 ms |
6240 KB |
Output is correct |
50 |
Correct |
153 ms |
15500 KB |
Output is correct |
51 |
Correct |
133 ms |
14208 KB |
Output is correct |
52 |
Correct |
158 ms |
15608 KB |
Output is correct |
53 |
Correct |
134 ms |
15648 KB |
Output is correct |
54 |
Correct |
148 ms |
16368 KB |
Output is correct |
55 |
Correct |
81 ms |
6280 KB |
Output is correct |