#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
struct FT{
vector<int> bit;
int n;
FT(int ns){
n = ns;
bit.resize(n + 1);
}
void upd(int v, int x){
while (v <= n){
bit[v] = max(bit[v], x);
v |= (v + 1);
}
}
int get(int v){
int out = 0;
while (v > 0){
out = max(out, bit[v]);
v = (v & (v + 1)) - 1;
}
return out;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, x; cin>>n>>x;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i];
}
auto lis = [&](vector<int> x){
vector<pii> all;
for (int i = 1; i <= n; i++){
all.pb({x[i], i});
}
sort(all.begin(), all.end());
vector<int> vv;
int i = 0, cc = 1;
while (i < n){
int j = i;
while (j < n && all[i] == all[j]){
x[all[j].ss] = cc;
j++;
}
vv.pb(all[i].ff);
i = j; cc++;
}
vector<int> :: iterator it;
FT T(n);
vector<int> dp(n + 1);
int ret = 0;
for (int i = 1; i <= n; i++){
it = lower_bound(vv.begin(), vv.end(), x[i]);
int j = (int) (it - vv.begin());
dp[i] = 1 + T.get(j);
ret = max(ret, dp[i]);
T.upd(j + 1, dp[i]);
}
return ret;
};
int out = lis(a);
for (int i = 1; i <= n; i++){
a[i] -= x;
out = max(out, lis(a));
}
for (int i = 1; i <= n; i++) a[i] += x;
for (int i = n; i > 0; i--){
a[i] += x;
out = max(out, lis(a));
}
cout<<out<<"\n";
}
# | 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... |