이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
const int INF = 1e9 + 1000;
int arr[N] , dp[N] , las[N] , last[N] , g[N] , f[N] , ls[N] , ans , n , x;
int32_t main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
fill(las , las + N , INF);
fill(last , last + N , INF);
fill(ls , ls + N , INF);
cin >> n >> x;
for(int i = 0 ; i < n ; i++)
cin >> arr[i];
for(int i = 0 ; i < n ; i++){
int low = 0 , high = n;
while(high - low > 1){
int mid = (high + low) >> 1;
if(las[mid] <= arr[i])
low = mid;
else
high = mid;
}
las[low + 1] = arr[i];
dp[i] = low + 1;
int l = 0 , r = n;
while(r - l > 1){
int mid = (r + l) >> 1;
if(last[mid] <= arr[i])
l = mid;
else
r = mid;
}
g[i] = l + 1;
last[low + 1] = arr[i] - x;
}
for(int i = 0 ; i < n ; i++){
int low = 0 , high = n;
while(high - low > 1){
int mid = (high + low) >> 1;
if(ls[mid] <= arr[i])
low = mid;
else
high = mid;
}
f[i] = low + 1;
f[i] = max(f[i] , g[i]);
ls[f[i]] = arr[i];
ans = max(ans , f[i]);
}
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... |