이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
const int mxN = 2e5+5;
int n, x, arr[mxN];
pii lis[mxN], inlis[mxN];
int last[mxN];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> x;
vector<int> temp;
for(int i = 1; i <= n; ++i) {
cin >> arr[i];
auto itr = lower_bound(temp.begin(), temp.end(), arr[i]);
if(itr == temp.end())
temp.emplace_back(arr[i]);
else
*itr = arr[i];
lis[i] = {temp[temp.size()-1], temp.size()};
}
temp.clear();
for(int i = n; i >= 1; --i) {
auto itr = lower_bound(temp.begin(), temp.end(), -arr[i]);
if(itr == temp.end())
temp.emplace_back(-arr[i]);
else
*itr = -arr[i];
inlis[i] = {-temp[temp.size()-1], temp.size()};
// cout << inlis[i].first << ' ' << inlis[i].second << '\n';
}
// int ans = 0;
int ans = lis[n].second;
for(int i = 1; i < n; ++i) {
pii t = {lis[i].first - x + 1, 0};
int j = lower_bound(inlis+i+1, inlis+n, t) - inlis;
int sum = lis[i].second + inlis[j].second;
if(t.first > inlis[j].first) continue;
if(sum > ans) {
ans = sum;
// cout << i << ' ' << j << '\n';
// cout << t.first << ' ';
}
}
cout << ans;
}
/*
8 7
7 3 5 12 -2 7 3 4
4 1
-9 -8 -7 -10
*/
# | 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... |