#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 ST{
vector<int> t;
int n;
ST(int ns){
n = ns;
t.resize(4 * n);
}
void upd(int v, int tl, int tr, int& p, int& x){
if (tl == tr){
t[v] = max(t[v], x);
return;
}
int tm = (tl + tr) / 2, vv = 2 * v;
if (p <= tm){
upd(vv, tl, tm, p, x);
}
else {
upd(vv + 1, tm + 1, tr, p, x);
}
t[v] = max(t[vv], t[vv + 1]);
}
void upd(int p, int x){
upd(1, 1, n, p, x);
}
int get(int v, int tl, int tr, int& p){
if (tl > p) return 0;
if (tr <= p){
return t[v];
}
int tm = (tl + tr) / 2, vv = 2 * v;
return max(get(vv, tl, tm, vv), get(vv + 1, tm + 1, tr, p));
}
int get(int p){
if (!p) return 0;
return get(1, 1, n, p);
}
};
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++;
}
ST T(n);
vector<int> dp(n + 1);
int ret = 0;
for (int i = 1; i <= n; i++){
dp[i] = 1 + T.get(x[i] - 1);
ret = max(ret, dp[i]);
T.upd(x[i], 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... |