이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 405;
const int M = 300005;
int a[M];
int seg[M << 1];
int n, d;
int dp[N][N][N];
int bt (int id, int mx, int la) {
if (id == n) return 0;
int& ret = dp[id][mx][la];
if (ret != -1) {
return ret;
}
if (id - la > d && mx != 0) return 0;
ret = max(bt(id + 1, mx, la), bt(id + 1, max(mx, a[id]), id) + (int) (a[id] > mx));
return ret;
}
int get (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 get(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return get(rs, mid + 1, r, s, e);
} else {
return max(get(rs, mid + 1, r, s, e), get(nd + 1, l, mid, s, e));
}
}
}
int get (int v, int e) {
if (v > e) return 0;
return get(0, 0, n, v, e);
}
void upd (int nd, int l, int r, int p, int v) {
if (l == r) return void(seg[nd] = max(seg[nd], v));
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);
}
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() + 1;
}
if (d < n) {
memset(dp, -1, sizeof dp);
cout << bt(0, 0, 0) << '\n';
return 0;
}
int ans = 1;
for (int i = n - 1; i >= 0; --i) {
int tmp = get(a[i] + 1, n) + 1;
upd(a[i], tmp);
ans = max(ans, tmp);
}
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... |