이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 3e5 + 9;
const long long inf = (long long) 1e18L;
long long n, x, a[N], dp[N], pd[N];
pair<long long, long long> suffix_lds_info[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 1;
fill(dp, dp + n, inf);
for (int i = n - 1; i >= 0; i--) {
int j = lower_bound(dp, dp + n, -a[i]) - dp;
dp[j] = -a[i];
ans = max(ans, j + 1);
suffix_lds_info[i] = {ans, -dp[ans - 1]};
}
fill(dp, dp + n, inf);
if (suffix_lds_info[0].second != a[0] && a[0] - x < suffix_lds_info[0].second) {
ans += 1;
}
for (int i = 0; i < n; i++) {
a[i] -= x;
int j = lower_bound(dp, dp + n, a[i]) - dp;
dp[j] = a[i];
if (i + 1 < n) {
int ns = suffix_lds_info[i + 1].second;
int sl = suffix_lds_info[i + 1].first;
j = lower_bound(dp, dp + n, ns) - dp;
j -= 1;
ans = max(ans, j + 1 + sl);
}
if (suffix_lds_info[i].second != a[i] + x && a[i] < suffix_lds_info[i].second) {
int ns = suffix_lds_info[i].second;
int sl = suffix_lds_info[i].first;
j = lower_bound(dp, dp + n, ns) - dp;
j -= 1;
ans = max(ans, j + 1 + sl);
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |