이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pb push_back
#define sz(v) ((int)v.size())
const ll inf = 1e16;
vector<int> nm;
int bs(int x) {
int l, r, m;
l = 0;
r = sz(nm);
while (l < r) {
m = (l+r)/2;
if (nm[m] <= x)
l = m+1;
else
r = m;
}
return l;
}
struct aib {
int n;
vector<int> f;
aib(int _n) : n(_n)
{
f.assign(n, 0);
}
void upd(int x, int v) {
f[x] = max(f[x], v);
for (; x < n; x |= (x+1))
f[x] = max(f[x], v);
}
int qry(int x) {
int r = 0;
for (; x >=0; x = (x&(x+1))-1)
r = max(f[x], r);
return r;
}
};
int main() {
int n, d;
cin >> n >> d;
vector<int> t(n);
for (int i = 0; i < n; ++i)
cin >> t[i];
nm = t;
sort(nm.begin(), nm.end());
nm.erase(unique(nm.begin(), nm.end()), nm.end());
aib z[2] {sz(nm)+5, sz(nm)+5};
for (auto x : t) {
z[1].upd(bs(x), 1 + z[1].qry(bs(x-1)));
z[1].upd(bs(x), 1 + z[0].qry(bs(x + d-1)));
z[0].upd(bs(x), 1 + z[0].qry(bs(x-1)));
}
cout << max(z[0].qry(sz(nm)+5), z[1].qry(sz(nm)+5)) << endl;;
}
# | 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... |