이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define mask(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
using namespace std;
const int mxN = 3e5 + 227;
const ll inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n , x;
int a[mxN];
int l[mxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("task.inp" , "r" , stdin);
//freopen("task.out" , "w" , stdout);
cin >> n >> x;
for(int i = 1 ; i <= n ; i++) cin >> a[i];
int res = 0;
vector<int> lis;
for(int i = 1 ; i <= n ; i++) {
int pos = lower_bound(lis.begin() , lis.end() , a[i]) - lis.begin();
l[i] = pos + 1;
if(pos == (int) lis.size()) lis.push_back(a[i]);
else lis[pos] = a[i];
maximize(res , l[i]);
}
lis.clear();
for(int i = n ; i >= 1 ; i--) {
int pos = lower_bound(lis.begin() , lis.end() , -(a[i] - x)) - lis.begin();
maximize(res , l[i] + pos);
pos = lower_bound(lis.begin() , lis.end() , -a[i]) - lis.begin();
if(pos == (int) lis.size()) lis.push_back(-a[i]);
else l[pos] = -a[i];
}
cout << res;
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... |