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>
using namespace std;
using ll = long long;
vector<int> magic2;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,x;
cin >> n >> x;
int temps[n];
for(int i = 0; i < n; i++) cin >> temps[i];
int longestIncreasing[n+1], largestNumber[n+1], longestIncreasing2[n+1];
vector<int> magic;
longestIncreasing[0]=0;
largestNumber[0]=1<<31;
longestIncreasing2[n]=0;
magic.push_back(temps[0]);
longestIncreasing[1]=1;
largestNumber[1]=-(temps[0]-x);
for(int i = 1; i < n; i++) {
int lb = lower_bound(begin(magic), end(magic), temps[i])-begin(magic);
if(lb==magic.size()) {
magic.push_back(temps[i]);
} else {
magic[lb]=temps[i];
}
longestIncreasing[i+1]=magic.size();
largestNumber[i+1]=-(magic.back()-x);
}
for(int i = 0; i < n; i++) {
temps[i]*=-1;
}
vector<int> magic2;
magic2.push_back(temps[n-1]);
if(temps[n-1]<largestNumber[n-1]) {
longestIncreasing2[n-1]=1;
} else {
longestIncreasing2[n-1]=0;
}
for(int i = n-2; i >= 0; i--) {
int lb = lower_bound(begin(magic2), end(magic2), temps[i])-begin(magic2);
if(lb==magic2.size()) {
magic2.push_back(temps[i]);
} else {
magic2[lb]=temps[i];
}
int lbb = lower_bound(begin(magic2), end(magic2), largestNumber[i])-begin(magic2);
if(lbb==magic2.size()) {
longestIncreasing2[i]=magic2.size();
} else if(magic2[lbb]==largestNumber[i]) {
longestIncreasing2[i]=lbb;
} else {
longestIncreasing2[i]=lbb+1;
}
}
int max = 0;
for(int i = 0; i <= n; i++) {
max=std::max(max, longestIncreasing[i]+longestIncreasing2[i]);
}
cout << max << endl;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(lb==magic.size()) {
| ~~^~~~~~~~~~~~~~
glo.cpp:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(lb==magic2.size()) {
| ~~^~~~~~~~~~~~~~~
glo.cpp:48:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if(lbb==magic2.size()) {
| ~~~^~~~~~~~~~~~~~~
# | 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... |