#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> ii;
typedef pair <int,ii> iii;
typedef pair <int,iii> iiii;
//#define int ll
#define F first
#define S second
#define pb push_back
#define mp make_pair
bool BIT(int u,int v) {return (u&(1<<v));}
int gen(int l,int r)
{
return l+(rand()%(r-l+1));
}
vector<int> rar;
int st[1600055][2];
int a[200005];
int x;
int n;
void upd(int id,int l,int r,int u,int t,int val)
{
if (l==r) {st[id][t]=max(st[id][t],val);return;}
int mid=(l+r)/2;
if (mid>=u) upd(id*2,l,mid,u,t,val);
else upd(id*2+1,mid+1,r,u,t,val);
st[id][t]=max(st[id*2][t],st[id*2+1][t]);
}
int get(int id,int l,int r,int u,int v,int t)
{
if (u>v) return 0;
if (l>v||r<u) return 0;
if (u<=l&&r<=v) return st[id][t];
int mid=(l+r)/2;
int g1=get(id*2,l,mid,u,v,t);
int g2=get(id*2+1,mid+1,r,u,v,t);
return max(g1,g2);
// return max(get(id*2,l,mid,u,v,t),get(id*2+1,mid+1,r,u,v,t));
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
srand(time(NULL));
// freopen("DAYDEP.inp","r",stdin);
// freopen("DAYDEP.out","w",stdout);
cin>>n>>x;
for(int i=1;i<=n;i++) cin>>a[i],rar.pb(a[i]),rar.pb(a[i]-x);
sort(rar.begin(),rar.end());
int res=0;
for(int i=1;i<=n;i++)
{
int id=lower_bound(rar.begin(),rar.end(),a[i]-x)-rar.begin()+1;
int dp0=1+get(1,1,2*n,1,id-1,0);
res=max(res,dp0);
int id1=lower_bound(rar.begin(),rar.end(),a[i])-rar.begin()+1;
int dp1=1+max(get(1,1,2*n,1,id1-1,1),get(1,1,2*n,1,id1-1,0));
res=max(res,dp1);
upd(1,1,2*n,id1,1,dp1);
upd(1,1,2*n,id,0,dp0);
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
13004 KB |
Output is correct |
2 |
Correct |
250 ms |
12816 KB |
Output is correct |
3 |
Correct |
230 ms |
13000 KB |
Output is correct |
4 |
Correct |
230 ms |
13120 KB |
Output is correct |
5 |
Correct |
125 ms |
8172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
3736 KB |
Output is correct |
2 |
Correct |
51 ms |
3800 KB |
Output is correct |
3 |
Correct |
51 ms |
3548 KB |
Output is correct |
4 |
Correct |
28 ms |
2608 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
32 ms |
3292 KB |
Output is correct |
7 |
Correct |
44 ms |
3700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
6636 KB |
Output is correct |
2 |
Correct |
110 ms |
6608 KB |
Output is correct |
3 |
Correct |
237 ms |
12996 KB |
Output is correct |
4 |
Correct |
121 ms |
8188 KB |
Output is correct |
5 |
Correct |
74 ms |
6352 KB |
Output is correct |
6 |
Correct |
130 ms |
11968 KB |
Output is correct |
7 |
Correct |
131 ms |
12740 KB |
Output is correct |
8 |
Correct |
95 ms |
6600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
239 ms |
13004 KB |
Output is correct |
28 |
Correct |
250 ms |
12816 KB |
Output is correct |
29 |
Correct |
230 ms |
13000 KB |
Output is correct |
30 |
Correct |
230 ms |
13120 KB |
Output is correct |
31 |
Correct |
125 ms |
8172 KB |
Output is correct |
32 |
Correct |
50 ms |
3736 KB |
Output is correct |
33 |
Correct |
51 ms |
3800 KB |
Output is correct |
34 |
Correct |
51 ms |
3548 KB |
Output is correct |
35 |
Correct |
28 ms |
2608 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
32 ms |
3292 KB |
Output is correct |
38 |
Correct |
44 ms |
3700 KB |
Output is correct |
39 |
Correct |
119 ms |
6636 KB |
Output is correct |
40 |
Correct |
110 ms |
6608 KB |
Output is correct |
41 |
Correct |
237 ms |
12996 KB |
Output is correct |
42 |
Correct |
121 ms |
8188 KB |
Output is correct |
43 |
Correct |
74 ms |
6352 KB |
Output is correct |
44 |
Correct |
130 ms |
11968 KB |
Output is correct |
45 |
Correct |
131 ms |
12740 KB |
Output is correct |
46 |
Correct |
95 ms |
6600 KB |
Output is correct |
47 |
Correct |
104 ms |
6608 KB |
Output is correct |
48 |
Correct |
104 ms |
6608 KB |
Output is correct |
49 |
Correct |
230 ms |
13000 KB |
Output is correct |
50 |
Correct |
117 ms |
8396 KB |
Output is correct |
51 |
Correct |
108 ms |
11204 KB |
Output is correct |
52 |
Correct |
153 ms |
12228 KB |
Output is correct |
53 |
Correct |
143 ms |
12484 KB |
Output is correct |
54 |
Correct |
137 ms |
12996 KB |
Output is correct |
55 |
Correct |
202 ms |
12868 KB |
Output is correct |