이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
int n,x;
cin >>n >> x;
vector<int> v(n);
for(int&i : v) cin >> i;
vector<int> suf(n+1, 0), lds(n+1, -1);
lds[0] = INF;
for(int i = n-1; i >= 0; i--) {
int l = 0, r = n, mo = n;
while(l <= r) {
int mid = (l + r) / 2;
if(lds[mid] >= v[i]) {
l = mid+1;
mo = mid;
}
else r = mid-1;
}
//cout << i << ": " << mo << endl;
mo++;
suf[i] = mo;
lds[mo] = v[i];
}
/*for(int i = 0; i < n; i++) cout << suf[i] << ' ';
cout << endl;*/
vector<int> dp(n+1, INF);
dp[0] = -1;
int mo = 0;
for(int i = 0; i < n; i++) {
int a = lower_bound(dp.begin(), dp.end(), v[i] + x) - dp.begin();
/*cout << i << ": ";
for(int i = 0; i <= n; i++) cout << dp[i] << ' ';
cout << endl << a << ", " << suf[i] << endl;*/
mo = max(mo, a-1 + suf[i]);
int j = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
dp[j] = v[i];
}
cout << mo;
}
# | 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... |