이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 300005;
int n, d;
int a[N];
int dp[N];
int seg[N << 1];
vector<int> in[N];
void upd (int nd, int l, int r, int p, int v) {
if (l == r) {
seg[nd] = v;
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (p <= mid) {
upd(nd + 1, l, mid, p, v);
} else {
upd(rs, mid + 1, r, p, v);
}
seg[nd] = max(seg[nd + 1], seg[rs]);
}
void upd (int p, int v) {
upd(0, 0, n, p, v);
}
int qry (int nd, int l, int r, int s, int e) {
if (l >= s && r <= e) {
return seg[nd];
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
return qry(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return qry(rs, mid + 1, r, s, e);
} else {
return max(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e));
}
}
}
int qry (int l, int r) {
l = max(l, 0);
return qry(0, 0, n, l, r);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> d;
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
in[a[i]].push_back(i);
}
int ans = 1;
for (int i = 0; i < n; ++i) {
for (int j : in[i]) {
dp[j] = qry(j - d, j) + 1;
ans = max(ans, dp[j]);
}
for (int j : in[i]) {
upd(j, dp[j]);
}
}
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... |