This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
using namespace std;
const long long int N = 1e6 + 5;
const long long int MOD = 1e9 + 7;
int main(){
fast;
long long int n, x;
cin >> n >> x;
long long int a[n];
for(long long int i = 0; i < n; ++i)
cin >> a[i];
vector<pair<long long int, long long int> > lis;
lis.push_back({a[0], 0});
for(long long int i = 1; i < n; ++i){
if(a[i] > lis.back().first){
lis.push_back({a[i], i});
continue;
}
long long int low = 0, high = lis.size() - 1, ans = -1;
while(low <= high){
long long int mid = (low + high) / 2;
if(lis[mid].first >= a[i]){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans == -1)
continue;
lis[ans] = {a[i], i};
}
long long int mx = lis.size(), l = INT_MAX, r = 0;
for(auto k : lis){
l = min(l, k.second);
r = max(r, k.second);
}
for(long long int i = l; i <= r; ++i)
a[i] += x;
vector<long long int> lis1;
lis1.push_back(a[0]);
for(long long int i = 1; i < n; ++i){
if(a[i] > lis1.back()){
lis1.push_back(a[i]);
continue;
}
long long int low = 0, high = lis1.size() - 1, ans = -1;
while(low <= high){
long long int mid = (low + high) / 2;
if(lis1[mid] >= a[i]){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans == -1)
continue;
lis1[ans] = a[i];
}
mx = max(mx, (long long int) lis1.size());
for(long long int i = l; i <= r; ++i)
a[i] -= 2*x;
lis1.clear();
lis1.push_back(a[0]);
for(long long int i = 1; i < n; ++i){
if(a[i] > lis1.back()){
lis1.push_back(a[i]);
continue;
}
long long int low = 0, high = lis1.size() - 1, ans = -1;
while(low <= high){
long long int mid = (low + high) / 2;
if(lis1[mid] >= a[i]){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans == -1)
continue;
lis1[ans] = a[i];
}
cout << max(mx, (long long int) lis1.size()) << '\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... |