#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
vector<int> lis(vector<int> &arr, int constX) {
vector<int> dp(arr.size());
set<pii> s;
for (int i = 0; i < arr.size();i++) {
int v = arr[i];
if (constX >= 0) {
auto it = s.lower_bound({v, 0});
if (s.empty()) dp[i] = 0;
else {
it = s.lower_bound({v + constX, 0});
bool remOld = false;
if (it != s.begin()) it--;
else remOld = true;
dp[i] = it->second - (remOld);
}
}
if (s.empty()) {
s.insert({v,1});
}
auto it = s.lower_bound({v,0});
bool remOld = true;
if (it == s.end()) {
it--;
remOld = false;
}
int p = it->second;
if (it->first > v || !remOld) {
if (remOld) s.erase(it);
s.emplace(v,p + (!remOld));
}
if (constX == -1)
dp[i] = p + !remOld;
}
return dp;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, x; cin >> n >> x;
vector<int> arr(n), revArr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
revArr[i] = -arr[i];
}
std::reverse(revArr.begin(), revArr.end());
auto before = lis(arr,-1), after = lis(revArr,x);
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, before[i] + after[n - 1 - i]);
if (ans == 3) {
int stop = 25;
}
}
cout << ans;
return 0;
}
Compilation message
glo.cpp: In function 'std::vector<int> lis(std::vector<int>&, int)':
glo.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (int i = 0; i < arr.size();i++) {
| ~~^~~~~~~~~~~~
glo.cpp: In function 'int main()':
glo.cpp:62:17: warning: unused variable 'stop' [-Wunused-variable]
62 | int stop = 25;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
3632 KB |
Output is correct |
2 |
Correct |
77 ms |
5460 KB |
Output is correct |
3 |
Correct |
74 ms |
5524 KB |
Output is correct |
4 |
Correct |
80 ms |
5460 KB |
Output is correct |
5 |
Correct |
81 ms |
9312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1072 KB |
Output is correct |
2 |
Correct |
17 ms |
1116 KB |
Output is correct |
3 |
Correct |
18 ms |
1116 KB |
Output is correct |
4 |
Correct |
16 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
19 ms |
2288 KB |
Output is correct |
7 |
Correct |
15 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2040 KB |
Output is correct |
2 |
Correct |
32 ms |
1872 KB |
Output is correct |
3 |
Correct |
68 ms |
3624 KB |
Output is correct |
4 |
Correct |
80 ms |
8044 KB |
Output is correct |
5 |
Correct |
40 ms |
4232 KB |
Output is correct |
6 |
Correct |
72 ms |
7760 KB |
Output is correct |
7 |
Correct |
69 ms |
7764 KB |
Output is correct |
8 |
Correct |
25 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
73 ms |
3632 KB |
Output is correct |
28 |
Correct |
77 ms |
5460 KB |
Output is correct |
29 |
Correct |
74 ms |
5524 KB |
Output is correct |
30 |
Correct |
80 ms |
5460 KB |
Output is correct |
31 |
Correct |
81 ms |
9312 KB |
Output is correct |
32 |
Correct |
17 ms |
1072 KB |
Output is correct |
33 |
Correct |
17 ms |
1116 KB |
Output is correct |
34 |
Correct |
18 ms |
1116 KB |
Output is correct |
35 |
Correct |
16 ms |
2392 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
19 ms |
2288 KB |
Output is correct |
38 |
Correct |
15 ms |
1280 KB |
Output is correct |
39 |
Correct |
32 ms |
2040 KB |
Output is correct |
40 |
Correct |
32 ms |
1872 KB |
Output is correct |
41 |
Correct |
68 ms |
3624 KB |
Output is correct |
42 |
Correct |
80 ms |
8044 KB |
Output is correct |
43 |
Correct |
40 ms |
4232 KB |
Output is correct |
44 |
Correct |
72 ms |
7760 KB |
Output is correct |
45 |
Correct |
69 ms |
7764 KB |
Output is correct |
46 |
Correct |
25 ms |
1884 KB |
Output is correct |
47 |
Correct |
38 ms |
2896 KB |
Output is correct |
48 |
Correct |
41 ms |
2908 KB |
Output is correct |
49 |
Correct |
74 ms |
5536 KB |
Output is correct |
50 |
Correct |
94 ms |
9300 KB |
Output is correct |
51 |
Correct |
62 ms |
8276 KB |
Output is correct |
52 |
Correct |
91 ms |
9440 KB |
Output is correct |
53 |
Correct |
64 ms |
9300 KB |
Output is correct |
54 |
Correct |
76 ms |
10068 KB |
Output is correct |
55 |
Correct |
57 ms |
5456 KB |
Output is correct |