#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define name "LIS"
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, b, a) for (int i = (b); i >= (a); i--)
template <class U, class V>
bool maximize(U &x, V y) {
if (x < y) { x = y; return true; }
return false;
}
template <class U, class V>
bool minimize(U &x, V y) {
if (x > y) { x = y; return true; }
return false;
}
const int INF = 2e9 + 7;
const int N = 3e5 + 5;
int a[N];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
if (fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
int n, d;
cin >> n >> d;
FOR(i, 1, n) cin >> a[i];
vector<int> f(n + 1, 0); f[0] = INF;
vector<int> suff(n + 1, 0);
int ans = 0;
FOD(i, n, 1) {
int idx = lower_bound(f.begin(), f.end(), a[i], greater<int>()) - f.begin();
suff[i] = idx;
f[idx] = a[i];
maximize(ans, idx);
}
f = vector<int>(n + 1, INF); f[0] = 0;
FOR(i, 1, n - 1) {
int idx = lower_bound(f.begin(), f.end(), a[i]) - f.begin();
f[idx] = a[i];
idx = lower_bound(f.begin(), f.end(), a[i + 1] + d) - f.begin();
maximize(ans, idx + suff[i + 1] - 1);
}
cout << ans;
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
376 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
3412 KB |
Output is correct |
2 |
Correct |
40 ms |
3420 KB |
Output is correct |
3 |
Correct |
38 ms |
3408 KB |
Output is correct |
4 |
Correct |
39 ms |
3412 KB |
Output is correct |
5 |
Correct |
29 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1112 KB |
Output is correct |
2 |
Correct |
9 ms |
1068 KB |
Output is correct |
3 |
Correct |
10 ms |
1068 KB |
Output is correct |
4 |
Correct |
7 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
9 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1884 KB |
Output is correct |
2 |
Correct |
18 ms |
2908 KB |
Output is correct |
3 |
Correct |
37 ms |
5460 KB |
Output is correct |
4 |
Correct |
30 ms |
4700 KB |
Output is correct |
5 |
Correct |
14 ms |
2392 KB |
Output is correct |
6 |
Correct |
27 ms |
4432 KB |
Output is correct |
7 |
Correct |
30 ms |
5212 KB |
Output is correct |
8 |
Correct |
16 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
376 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
39 ms |
3412 KB |
Output is correct |
28 |
Correct |
40 ms |
3420 KB |
Output is correct |
29 |
Correct |
38 ms |
3408 KB |
Output is correct |
30 |
Correct |
39 ms |
3412 KB |
Output is correct |
31 |
Correct |
29 ms |
3420 KB |
Output is correct |
32 |
Correct |
10 ms |
1112 KB |
Output is correct |
33 |
Correct |
9 ms |
1068 KB |
Output is correct |
34 |
Correct |
10 ms |
1068 KB |
Output is correct |
35 |
Correct |
7 ms |
1116 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
7 ms |
1116 KB |
Output is correct |
38 |
Correct |
9 ms |
1116 KB |
Output is correct |
39 |
Correct |
18 ms |
1884 KB |
Output is correct |
40 |
Correct |
18 ms |
2908 KB |
Output is correct |
41 |
Correct |
37 ms |
5460 KB |
Output is correct |
42 |
Correct |
30 ms |
4700 KB |
Output is correct |
43 |
Correct |
14 ms |
2392 KB |
Output is correct |
44 |
Correct |
27 ms |
4432 KB |
Output is correct |
45 |
Correct |
30 ms |
5212 KB |
Output is correct |
46 |
Correct |
16 ms |
2908 KB |
Output is correct |
47 |
Correct |
19 ms |
2908 KB |
Output is correct |
48 |
Correct |
19 ms |
2904 KB |
Output is correct |
49 |
Correct |
40 ms |
5460 KB |
Output is correct |
50 |
Correct |
28 ms |
4696 KB |
Output is correct |
51 |
Correct |
25 ms |
3416 KB |
Output is correct |
52 |
Correct |
30 ms |
4852 KB |
Output is correct |
53 |
Correct |
29 ms |
4824 KB |
Output is correct |
54 |
Correct |
32 ms |
5456 KB |
Output is correct |
55 |
Correct |
33 ms |
5468 KB |
Output is correct |