이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, x, ans = 0;
cin >> n >> x;
vi a(n);
for(int &i : a)
cin >> i;
// longest increasing subsequence ending at i
vi lis, at_lis(n);
for(int i = 0; i < n; i++){
int pos = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin();
if(pos == sz(lis))
lis.emplace_back(a[i]);
else
lis[pos] = a[i];
at_lis[i] = pos + 1;
}
// longest decreasing subsequence ending at i of reverse
// = longest increasing subsequence starting at i
lis = vi(n, INT32_MAX);
for(int i = n - 1; i >= 0; i--){
int pos = lower_bound(lis.begin(), lis.end(), -a[i] + x) - lis.begin();
/*if(at_lis[i] + pos > ans)
cout << "i: " << i << " val: " << at_lis[i] + pos << "\n";*/
ans = max(ans, at_lis[i] + pos);
int insert_pos = lower_bound(lis.begin(), lis.end(), -a[i]) - lis.begin();
lis[insert_pos] = -a[i];
}
cout << ans;
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... |