이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5, INF = 2e9 + 7;
int nr;
int sol[1 + N], poz[1 + N], scm[1 + N];
int a[1 + N];
inline int get (int n, int orient) {
int st, dr, p;
st = 1; dr = nr;
if (orient)
p = nr + 1;
else
p = 0;
while (st <= dr) {
int mij = (st + dr) / 2;
if ((sol[mij] > n && orient) || (sol[mij] < n && !orient)) {
dr = mij - 1;
p = mij;
}
else
st = mij + 1;
}
return p;
}
int main() {
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++)
cin >> a[i];
sol[1] = INF;
nr = 1;
for (int i = n; i > 0; i--) {
if (a[i] < sol[nr]) {
nr++;
poz[i] = nr;
sol[nr] = a[i];
}
else {
int p = get (a[i], 0);
sol[p] = a[i];
poz[i] = p;
}
}
sol[1] = 0;
nr = 1;
int ans = 0;
for (int i = 1; i <= n; i++) {
int p;
if (a[i] + x > sol[nr])
p = nr + 1;
else
p = get (a[i], x + 1);
//cout << p << "\n";
ans = max (ans, poz[i] + p - 3);
if (a[i] > sol[nr]) {
nr++;
sol[nr] = a[i];
}
else {
int p = get (a[i], 1);
sol[p] = a[i];
}
}
cout << ans << "\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... |