#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 200005
typedef long long ll;
using namespace std;
int n,d;
int niz[MAXN];
set<int> s;
map<int,int> m;
int tren=0;
int seg1[MAXN*4],seg2[MAXN*4];
void dodaj(int l,int d,int p,int x,int k,int *seg){
//if(seg==seg2)printf(" %d %d kek\n",p,x);
//else printf(" %d %d lel\n",p,x);
if(l==d){
seg[k]=max(seg[k],x);
return;
}
int mid=(l+d)/2;
if(p<=mid)dodaj(l,mid,p,x,k+k,seg);
else dodaj(mid+1,d,p,x,k+k+1,seg);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
int dobij(int l,int d,int tl,int td,int k,int *seg){
if(l>td || d<tl)return 0;
if(l>=tl && d<=td)return seg[k];
int mid=(l+d)/2;
return max(dobij(l,mid,tl,td,k+k,seg),dobij(mid+1,d,tl,td,k+k+1,seg));
}
int dp[MAXN][2];
int res;
int main()
{
scanf("%d %d", &n, &d);
for(int i=1;i<=n;i++)
scanf("%d",niz+i);
for(int i=1;i<=n;i++)
s.insert(niz[i]);
for(auto x:s){
tren++;
m[x]=tren;
}
for(int i=1;i<=n;i++){
int tren=m[niz[i]];
if(tren==1){
dp[i][0]=1;
if(d!=0)dp[i][1]=1+dobij(1,n,1,m[*(--s.lower_bound(niz[i]+d))],1,seg1);
else dp[i][1]=1;
dodaj(1,n,tren,dp[i][0],1,seg1);
dodaj(1,n,tren,dp[i][1],1,seg2);
//printf(" %d %d\n",niz[i],*(--s.lower_bound(niz[i]+d)));
}else{
dp[i][0]=1+dobij(1,n,1,tren-1,1,seg1);
dp[i][1]=max(1+dobij(1,n,1,m[*(--s.lower_bound(niz[i]+d))],1,seg1), 1+dobij(1,n,1,tren-1,1,seg2));
dodaj(1,n,tren,dp[i][0],1,seg1);
dodaj(1,n,tren,dp[i][1],1,seg2);
//printf(" %d %d\n",niz[i],*(--s.lower_bound(niz[i]+d)));
}
//printf(" %d %d\n",dp[i][0],dp[i][1]);
res=max(res,dp[i][1]);
}
printf("%d",res);
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &d);
~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",niz+i);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
380 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
873 ms |
25600 KB |
Output is correct |
2 |
Correct |
884 ms |
27640 KB |
Output is correct |
3 |
Correct |
916 ms |
27584 KB |
Output is correct |
4 |
Correct |
913 ms |
27632 KB |
Output is correct |
5 |
Correct |
295 ms |
15316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
6604 KB |
Output is correct |
2 |
Correct |
153 ms |
7296 KB |
Output is correct |
3 |
Correct |
153 ms |
7156 KB |
Output is correct |
4 |
Correct |
62 ms |
4088 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
66 ms |
4068 KB |
Output is correct |
7 |
Correct |
109 ms |
7188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
307 ms |
12920 KB |
Output is correct |
2 |
Correct |
302 ms |
14072 KB |
Output is correct |
3 |
Correct |
717 ms |
27512 KB |
Output is correct |
4 |
Correct |
354 ms |
15304 KB |
Output is correct |
5 |
Correct |
204 ms |
13560 KB |
Output is correct |
6 |
Correct |
382 ms |
25764 KB |
Output is correct |
7 |
Correct |
360 ms |
26420 KB |
Output is correct |
8 |
Correct |
240 ms |
13956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
380 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
873 ms |
25600 KB |
Output is correct |
28 |
Correct |
884 ms |
27640 KB |
Output is correct |
29 |
Correct |
916 ms |
27584 KB |
Output is correct |
30 |
Correct |
913 ms |
27632 KB |
Output is correct |
31 |
Correct |
295 ms |
15316 KB |
Output is correct |
32 |
Correct |
153 ms |
6604 KB |
Output is correct |
33 |
Correct |
153 ms |
7296 KB |
Output is correct |
34 |
Correct |
153 ms |
7156 KB |
Output is correct |
35 |
Correct |
62 ms |
4088 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
66 ms |
4068 KB |
Output is correct |
38 |
Correct |
109 ms |
7188 KB |
Output is correct |
39 |
Correct |
307 ms |
12920 KB |
Output is correct |
40 |
Correct |
302 ms |
14072 KB |
Output is correct |
41 |
Correct |
717 ms |
27512 KB |
Output is correct |
42 |
Correct |
354 ms |
15304 KB |
Output is correct |
43 |
Correct |
204 ms |
13560 KB |
Output is correct |
44 |
Correct |
382 ms |
25764 KB |
Output is correct |
45 |
Correct |
360 ms |
26420 KB |
Output is correct |
46 |
Correct |
240 ms |
13956 KB |
Output is correct |
47 |
Correct |
368 ms |
14008 KB |
Output is correct |
48 |
Correct |
370 ms |
14072 KB |
Output is correct |
49 |
Correct |
923 ms |
27512 KB |
Output is correct |
50 |
Correct |
300 ms |
15480 KB |
Output is correct |
51 |
Correct |
273 ms |
15224 KB |
Output is correct |
52 |
Correct |
425 ms |
26872 KB |
Output is correct |
53 |
Correct |
417 ms |
26896 KB |
Output is correct |
54 |
Correct |
386 ms |
27600 KB |
Output is correct |
55 |
Correct |
627 ms |
27672 KB |
Output is correct |