#include <bits/stdc++.h>
#include <iostream>
#include<vector>
using namespace std;
typedef long long ll;
const int sz=5e5+10;
const int sz1=1e6+1;
const int inf=1e9 + 7;
const int mod = 1e9 + 7;
int n,m,k,w;
long long d;
long long a[sz];
long long dp[sz];
long long bit[sz];
long long bit1[sz];
void upd0(int x,int diff){
for (int i = x; i < sz; i |= i + 1)
bit[i]= max(bit[i],(1ll)*diff);
}
long long query0(int x){
long long res = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
res = max(res,bit[i]);
return res;
}
void upd1(int x,int diff){
for (int i = x; i < sz; i |= i + 1)
bit1[i]= max(bit1[i],(1ll)*diff);
}
long long query1(int x){
long long res = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
res = max(res,bit1[i]);
return res;
}
int main(){
cin>>n>>d;
vector<long long>cor;
for(int i = 1; i <= n; i++){
cin>>a[i];
cor.push_back(a[i]);
cor.push_back(a[i] - d);
}
unordered_map<long long,int>mp;
sort(cor.begin(),cor.end());
//cor.erase(unique(cor.begin(),cor.end()),cor.end());
for(int i = 0; i < cor.size(); i++){
mp[cor[i]] = i + 1;
}
int ans = 0;
for(int i = 1; i <= n; i++){
int down = query1(mp[a[i] - d] - 1);
int cur = query0(mp[a[i]] - 1);
ans = max(ans, max(cur,down) + 1);
upd0(mp[a[i]], 1 + cur);
upd0(mp[a[i] - d], 1 + down);
upd1(mp[a[i] - d], 1 + down);
}
cout<<ans<<endl;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0; i < cor.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
312 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 |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
312 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 |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
440 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
20840 KB |
Output is correct |
2 |
Correct |
233 ms |
20780 KB |
Output is correct |
3 |
Correct |
228 ms |
20740 KB |
Output is correct |
4 |
Correct |
248 ms |
20840 KB |
Output is correct |
5 |
Correct |
110 ms |
12944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
7484 KB |
Output is correct |
2 |
Correct |
52 ms |
7480 KB |
Output is correct |
3 |
Correct |
52 ms |
7600 KB |
Output is correct |
4 |
Correct |
32 ms |
4772 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
26 ms |
5360 KB |
Output is correct |
7 |
Correct |
43 ms |
6336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
13980 KB |
Output is correct |
2 |
Correct |
160 ms |
13996 KB |
Output is correct |
3 |
Correct |
376 ms |
27900 KB |
Output is correct |
4 |
Correct |
159 ms |
17008 KB |
Output is correct |
5 |
Correct |
68 ms |
13996 KB |
Output is correct |
6 |
Correct |
131 ms |
26716 KB |
Output is correct |
7 |
Correct |
160 ms |
26768 KB |
Output is correct |
8 |
Correct |
121 ms |
13976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
312 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 |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
440 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
243 ms |
20840 KB |
Output is correct |
28 |
Correct |
233 ms |
20780 KB |
Output is correct |
29 |
Correct |
228 ms |
20740 KB |
Output is correct |
30 |
Correct |
248 ms |
20840 KB |
Output is correct |
31 |
Correct |
110 ms |
12944 KB |
Output is correct |
32 |
Correct |
50 ms |
7484 KB |
Output is correct |
33 |
Correct |
52 ms |
7480 KB |
Output is correct |
34 |
Correct |
52 ms |
7600 KB |
Output is correct |
35 |
Correct |
32 ms |
4772 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
26 ms |
5360 KB |
Output is correct |
38 |
Correct |
43 ms |
6336 KB |
Output is correct |
39 |
Correct |
150 ms |
13980 KB |
Output is correct |
40 |
Correct |
160 ms |
13996 KB |
Output is correct |
41 |
Correct |
376 ms |
27900 KB |
Output is correct |
42 |
Correct |
159 ms |
17008 KB |
Output is correct |
43 |
Correct |
68 ms |
13996 KB |
Output is correct |
44 |
Correct |
131 ms |
26716 KB |
Output is correct |
45 |
Correct |
160 ms |
26768 KB |
Output is correct |
46 |
Correct |
121 ms |
13976 KB |
Output is correct |
47 |
Correct |
134 ms |
15712 KB |
Output is correct |
48 |
Correct |
142 ms |
15772 KB |
Output is correct |
49 |
Correct |
364 ms |
31356 KB |
Output is correct |
50 |
Correct |
147 ms |
19040 KB |
Output is correct |
51 |
Correct |
87 ms |
15048 KB |
Output is correct |
52 |
Correct |
111 ms |
22008 KB |
Output is correct |
53 |
Correct |
134 ms |
29124 KB |
Output is correct |
54 |
Correct |
151 ms |
29772 KB |
Output is correct |
55 |
Correct |
236 ms |
26424 KB |
Output is correct |