#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1ll << 50;
int calcLIS(std::vector<i64> T) {
std::vector<i64> dp(T.size() + 1, inf);
for (const auto e : T) {
auto itr = std::lower_bound(dp.begin(), dp.end(), e);
*itr = e;
}
return (int)(std::lower_bound(dp.begin(), dp.end(), inf) - dp.begin());
}
int solveNaive(std::vector<i64> T, i64 X) {
int ans = 0;
for (int i = (int)T.size() - 1; i >= 0; --i) {
T[i] += X;
ans = std::max(ans, calcLIS(T));
}
return ans;
}
int solve(std::vector<i64> T, i64 X) {
std::set<std::pair<i64, int>> dp1, dp2;
dp1.insert({0, 0});
dp2.insert({0, 0});
for (const auto v : T) {
// normal
auto itr = dp2.lower_bound({v, 0});
--itr;
int l = itr->second;
dp2.insert({v, l + 1});
itr = dp2.upper_bound({v, l + 1});
while (itr != dp2.end() and itr->second <= l + 1) {
itr = dp2.erase(itr);
}
// special
itr = dp1.lower_bound({v + X, 0});
std::pair<i64, int> p = {-1, -1};
--itr;
p = std::make_pair(v, itr->second + 1);
itr = dp2.lower_bound({v, 1 << 30});
--itr;
if (itr->second < p.second) {
dp2.insert(p);
itr = dp2.lower_bound(p);
--itr;
if (itr->first == v) {
dp2.erase(itr);
}
itr = dp2.upper_bound(p);
while (itr != dp2.end() and itr->second <= p.second) {
itr = dp2.erase(itr);
}
}
// normal
itr = dp1.lower_bound(std::make_pair(v, 0));
--itr;
l = itr->second;
dp1.insert({v, l + 1});
itr = dp1.upper_bound({v, l + 1});
while (itr != dp1.end() and itr->second <= l + 1) {
itr = dp1.erase(itr);
}
}
return dp2.rbegin()->second;
}
int main() {
int N;
i64 X;
std::cin >> N >> X;
std::vector<i64> T(N);
for (auto &e : T) {
std::cin >> e;
}
std::cout << solve(T, X) << std::endl;
/*
std::mt19937 mt(100);
std::uniform_int_distribution<i64> dist(1, 10000000);
int cases = 10000;
while (cases--) {
int N = 100;
std::vector<i64> T(N);
for (auto &e : T) e = dist(mt);
i64 X = dist(mt);
if (solve(T, X) != solveNaive(T, X)) {
std::cout << N << " " << X << std::endl;
for (const auto e : T) std::cout << e << ' ';
std::cout << std::endl;
}
}
*/
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
3512 KB |
Output is correct |
2 |
Correct |
199 ms |
5420 KB |
Output is correct |
3 |
Correct |
194 ms |
5452 KB |
Output is correct |
4 |
Correct |
218 ms |
5424 KB |
Output is correct |
5 |
Correct |
209 ms |
17072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1116 KB |
Output is correct |
2 |
Correct |
47 ms |
1600 KB |
Output is correct |
3 |
Correct |
47 ms |
1576 KB |
Output is correct |
4 |
Correct |
40 ms |
4496 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
54 ms |
4436 KB |
Output is correct |
7 |
Correct |
41 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
1856 KB |
Output is correct |
2 |
Correct |
87 ms |
2880 KB |
Output is correct |
3 |
Correct |
183 ms |
5324 KB |
Output is correct |
4 |
Correct |
150 ms |
10800 KB |
Output is correct |
5 |
Correct |
124 ms |
8652 KB |
Output is correct |
6 |
Correct |
188 ms |
16360 KB |
Output is correct |
7 |
Correct |
194 ms |
17004 KB |
Output is correct |
8 |
Correct |
88 ms |
2888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
199 ms |
3512 KB |
Output is correct |
28 |
Correct |
199 ms |
5420 KB |
Output is correct |
29 |
Correct |
194 ms |
5452 KB |
Output is correct |
30 |
Correct |
218 ms |
5424 KB |
Output is correct |
31 |
Correct |
209 ms |
17072 KB |
Output is correct |
32 |
Correct |
45 ms |
1116 KB |
Output is correct |
33 |
Correct |
47 ms |
1600 KB |
Output is correct |
34 |
Correct |
47 ms |
1576 KB |
Output is correct |
35 |
Correct |
40 ms |
4496 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
54 ms |
4436 KB |
Output is correct |
38 |
Correct |
41 ms |
1624 KB |
Output is correct |
39 |
Correct |
90 ms |
1856 KB |
Output is correct |
40 |
Correct |
87 ms |
2880 KB |
Output is correct |
41 |
Correct |
183 ms |
5324 KB |
Output is correct |
42 |
Correct |
150 ms |
10800 KB |
Output is correct |
43 |
Correct |
124 ms |
8652 KB |
Output is correct |
44 |
Correct |
188 ms |
16360 KB |
Output is correct |
45 |
Correct |
194 ms |
17004 KB |
Output is correct |
46 |
Correct |
88 ms |
2888 KB |
Output is correct |
47 |
Correct |
113 ms |
2976 KB |
Output is correct |
48 |
Correct |
97 ms |
2852 KB |
Output is correct |
49 |
Correct |
204 ms |
5444 KB |
Output is correct |
50 |
Correct |
208 ms |
17056 KB |
Output is correct |
51 |
Correct |
192 ms |
15904 KB |
Output is correct |
52 |
Correct |
259 ms |
17136 KB |
Output is correct |
53 |
Correct |
206 ms |
17100 KB |
Output is correct |
54 |
Correct |
201 ms |
17800 KB |
Output is correct |
55 |
Correct |
178 ms |
5568 KB |
Output is correct |