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;
#define int long long
int n, x, t[200005], ans = 0;
// int binser(set<int, greater<int>> memo, int find) {
// }
void solve(int l, int r, int s) {
// cout << l << " " << r << " " << s << endl;
map<int, int> maks;
set<int, greater<int>> memo;
set<int>::iterator it;
int cur;
for (int i = l; i <= r; i++) {
t[i] += s;
}
stack<int> st;
int temp;
for (int i = 1; i <= n; i++) {
while (!st.empty()) {
if (t[i] <= st.top()) st.pop();
else break;
}
st.push(t[i]);
// pq.push(t[i]);
memo.insert(t[i]);
temp = st.size();
maks[t[i]] = max(maks[t[i]], temp);
// int cur = pq.top();
// pq.pop();
// maks[t[i]] = max(maks[t[i]], maks[pq.top()]+1);
// pq.push(cur);
if (memo.size() > 1) {
// it = memo.begin();
// it++;
// cur = *it;
// maks[t[i]] = max(maks[t[i]], maks[cur]+1);
// binser
// cout << "set : ";
for (it = memo.begin(); it != memo.end(); it++) {
if ((*it) == t[i]) break;
// cout << *it << " ";
}
// cout << endl;
// it++;
it++;
if (it != memo.end()) {
maks[t[i]] = max(maks[t[i]], maks[*it]+1);
}
// cout << cur << endl;
// maks[t[i]] = max(maks[t[i]], maks[cur]+1);
}
temp = maks[t[i]];
// cout << i << " " << t[i] << " " << temp << endl;
ans = max(temp, ans);
}
for (int i = l; i <= r; i++) {
t[i] -= s;
}
}
signed main() {
cin >> n >> x;
for (int i = 1; i <= n; i++) cin >> t[i];
if (x == 0) {
solve(1, n, 0);
cout << ans << endl;
return 0;
}
for (int l = 1; l <= n; l++) {
for (int r = l; r <= n; r++) {
for (int s = -x; s <= x; s++) {
solve(l, r, s);
}
}
}
cout << ans << endl;
}
Compilation message (stderr)
glo.cpp: In function 'void solve(long long int, long long int, long long int)':
glo.cpp:17:7: warning: unused variable 'cur' [-Wunused-variable]
17 | int cur;
| ^~~
# | 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... |