#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
int dp1[200005];
int dp2[200005];
int niz[200005];
int bit[2000005];
cc_hash_table <int, int> u;
int getmax(int x){
int res = 0;
while(x){
res = max(res, bit[x]);
x -= x & -x;
}
return res;
}
void addbit(int x, int val){
while(x <= 1000000){
bit[x] = max(bit[x], val);
x += x & -x;
}
}
void clearbit(int n){
for(int i=1; i<=n; i++) bit[i] = 0;
}
int main() {
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
int n, x;
cin >> n >> x;
vector <int> vec;
for(int i=1; i<=n; i++){
cin >> niz[i];
vec.push_back(niz[i]);
vec.push_back(niz[i] + x);
}
sort(vec.begin(), vec.end());
int cnt = 0;
for(auto c : vec){
if(!u[c]) u[c] = ++cnt;
}
clearbit(cnt+5);
for(int i=1; i<=n; i++){
dp1[i] = 1 + getmax(u[niz[i]] - 1);
addbit(u[niz[i]], dp1[i]);
}
clearbit(cnt+5);
for(int i=n; i>=1; i--){
dp2[i] = 1 + getmax(cnt+4-u[niz[i]] - 1);
addbit(cnt+4-u[niz[i]], dp2[i]);
}
clearbit(cnt+5);
int res = 0;
for(int i=1; i<=n; i++){
res = max(res, dp1[i]);
res = max(res, dp2[i] + getmax(u[niz[i] + x] - 1));
addbit(u[niz[i]], dp1[i]);
}
cout << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
17512 KB |
Output is correct |
2 |
Correct |
216 ms |
17340 KB |
Output is correct |
3 |
Correct |
209 ms |
17232 KB |
Output is correct |
4 |
Correct |
241 ms |
17468 KB |
Output is correct |
5 |
Correct |
85 ms |
10920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
7300 KB |
Output is correct |
2 |
Correct |
42 ms |
7400 KB |
Output is correct |
3 |
Correct |
44 ms |
7480 KB |
Output is correct |
4 |
Correct |
24 ms |
4428 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
17 ms |
4368 KB |
Output is correct |
7 |
Correct |
33 ms |
7352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
14804 KB |
Output is correct |
2 |
Correct |
164 ms |
15592 KB |
Output is correct |
3 |
Correct |
355 ms |
28608 KB |
Output is correct |
4 |
Correct |
138 ms |
16512 KB |
Output is correct |
5 |
Correct |
47 ms |
14012 KB |
Output is correct |
6 |
Correct |
93 ms |
26860 KB |
Output is correct |
7 |
Correct |
102 ms |
27440 KB |
Output is correct |
8 |
Correct |
95 ms |
14348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
336 KB |
Output is correct |
6 |
Correct |
0 ms |
336 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
0 ms |
336 KB |
Output is correct |
17 |
Correct |
0 ms |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
242 ms |
17512 KB |
Output is correct |
28 |
Correct |
216 ms |
17340 KB |
Output is correct |
29 |
Correct |
209 ms |
17232 KB |
Output is correct |
30 |
Correct |
241 ms |
17468 KB |
Output is correct |
31 |
Correct |
85 ms |
10920 KB |
Output is correct |
32 |
Correct |
40 ms |
7300 KB |
Output is correct |
33 |
Correct |
42 ms |
7400 KB |
Output is correct |
34 |
Correct |
44 ms |
7480 KB |
Output is correct |
35 |
Correct |
24 ms |
4428 KB |
Output is correct |
36 |
Correct |
0 ms |
336 KB |
Output is correct |
37 |
Correct |
17 ms |
4368 KB |
Output is correct |
38 |
Correct |
33 ms |
7352 KB |
Output is correct |
39 |
Correct |
151 ms |
14804 KB |
Output is correct |
40 |
Correct |
164 ms |
15592 KB |
Output is correct |
41 |
Correct |
355 ms |
28608 KB |
Output is correct |
42 |
Correct |
138 ms |
16512 KB |
Output is correct |
43 |
Correct |
47 ms |
14012 KB |
Output is correct |
44 |
Correct |
93 ms |
26860 KB |
Output is correct |
45 |
Correct |
102 ms |
27440 KB |
Output is correct |
46 |
Correct |
95 ms |
14348 KB |
Output is correct |
47 |
Correct |
162 ms |
15060 KB |
Output is correct |
48 |
Correct |
149 ms |
14644 KB |
Output is correct |
49 |
Correct |
349 ms |
30200 KB |
Output is correct |
50 |
Correct |
128 ms |
16480 KB |
Output is correct |
51 |
Correct |
56 ms |
13480 KB |
Output is correct |
52 |
Correct |
71 ms |
16696 KB |
Output is correct |
53 |
Correct |
88 ms |
27732 KB |
Output is correct |
54 |
Correct |
107 ms |
28468 KB |
Output is correct |
55 |
Correct |
234 ms |
28016 KB |
Output is correct |