#include <iostream>
#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 |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
508 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 |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
17264 KB |
Output is correct |
2 |
Correct |
229 ms |
17316 KB |
Output is correct |
3 |
Correct |
223 ms |
17328 KB |
Output is correct |
4 |
Correct |
215 ms |
17296 KB |
Output is correct |
5 |
Correct |
88 ms |
10896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
7312 KB |
Output is correct |
2 |
Correct |
41 ms |
7340 KB |
Output is correct |
3 |
Correct |
41 ms |
7428 KB |
Output is correct |
4 |
Correct |
22 ms |
4424 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
16 ms |
4424 KB |
Output is correct |
7 |
Correct |
35 ms |
7388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
14888 KB |
Output is correct |
2 |
Correct |
138 ms |
15576 KB |
Output is correct |
3 |
Correct |
333 ms |
28424 KB |
Output is correct |
4 |
Correct |
124 ms |
16508 KB |
Output is correct |
5 |
Correct |
51 ms |
13968 KB |
Output is correct |
6 |
Correct |
83 ms |
26804 KB |
Output is correct |
7 |
Correct |
92 ms |
27440 KB |
Output is correct |
8 |
Correct |
92 ms |
14392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
508 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 |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
208 ms |
17264 KB |
Output is correct |
28 |
Correct |
229 ms |
17316 KB |
Output is correct |
29 |
Correct |
223 ms |
17328 KB |
Output is correct |
30 |
Correct |
215 ms |
17296 KB |
Output is correct |
31 |
Correct |
88 ms |
10896 KB |
Output is correct |
32 |
Correct |
42 ms |
7312 KB |
Output is correct |
33 |
Correct |
41 ms |
7340 KB |
Output is correct |
34 |
Correct |
41 ms |
7428 KB |
Output is correct |
35 |
Correct |
22 ms |
4424 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
16 ms |
4424 KB |
Output is correct |
38 |
Correct |
35 ms |
7388 KB |
Output is correct |
39 |
Correct |
163 ms |
14888 KB |
Output is correct |
40 |
Correct |
138 ms |
15576 KB |
Output is correct |
41 |
Correct |
333 ms |
28424 KB |
Output is correct |
42 |
Correct |
124 ms |
16508 KB |
Output is correct |
43 |
Correct |
51 ms |
13968 KB |
Output is correct |
44 |
Correct |
83 ms |
26804 KB |
Output is correct |
45 |
Correct |
92 ms |
27440 KB |
Output is correct |
46 |
Correct |
92 ms |
14392 KB |
Output is correct |
47 |
Correct |
121 ms |
15104 KB |
Output is correct |
48 |
Correct |
132 ms |
14736 KB |
Output is correct |
49 |
Correct |
345 ms |
30148 KB |
Output is correct |
50 |
Correct |
120 ms |
16532 KB |
Output is correct |
51 |
Correct |
58 ms |
13492 KB |
Output is correct |
52 |
Correct |
79 ms |
16596 KB |
Output is correct |
53 |
Correct |
86 ms |
27696 KB |
Output is correct |
54 |
Correct |
94 ms |
28432 KB |
Output is correct |
55 |
Correct |
205 ms |
28008 KB |
Output is correct |