This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int N, X;
int A[200005];
int last[200005];
int jumped[200005];
// two state LIS
int LIS() {
for (int i = 0; i <= N; i++) last[i] = INF, jumped[i] = INF;
last[0] = -INF;
jumped[0] = -INF;
for (int i = 0; i < N; i++) {
int j = upper_bound(last, last + N + 1, A[i]) - last;
if (last[j - 1] < A[i] && A[i] < last[j]) last[j] = A[i];
j = upper_bound(jumped, jumped + N + 1, A[i] - X) - jumped;
if (jumped[j - 1] < A[i] - X && A[i] - X < jumped[j]) jumped[j] = A[i] - X;
j = upper_bound(jumped, jumped + N + 1, A[i]) - jumped;
if (jumped[j - 1] < A[i] && A[i] < jumped[j]) jumped[j] = A[i];
}
int res = 0;
for (int i = 0; i <= N; i++) {
if (last[i] < INF) res = max(res, i);
if (jumped[i] < INF) res = max(res, i);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> X;
for (int i = 0; i < N; i++) cin >> A[i];
int ans = LIS();
cout << ans << "\n";
}
# | 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... |