이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
const int mod = 998244353;
const int inf = 1e9 + 20;
const int N = 1e5+5;
struct SEGTMN{
vector<int> tree;
void init(int n){
tree.assign(4*n, inf);
}
void update(int ind, int l, int r, int pos, int val){
if(l == r){
tree[ind] = val;
}
else{
int m = (l + r)/2;
if(pos <= m) update(ind*2, l, m, pos, val);
else update(ind*2+1, m+1, r, pos, val);
tree[ind] = min(tree[ind*2], tree[ind*2+1]);
}
}
int query(int ind, int l, int r, int ql, int qr){
if(l > r || l > qr || r < ql) return inf;
if(l >= ql && r <= qr) return tree[ind];
else{
int m = (l + r)/2;
return min(query(ind*2, l, m, ql, qr), query(ind*2+1, m+1, r, ql, qr));
}
}
};
struct SEGTMX{
vector<int> tree;
void init(int n){
tree.assign(4*n, 0);
}
void update(int ind, int l, int r, int pos, int val){
if(l == r){
tree[ind] = val;
}
else{
int m = (l + r)/2;
if(pos <= m) update(ind*2, l, m, pos, val);
else update(ind*2+1, m+1, r, pos, val);
tree[ind] = max(tree[ind*2], tree[ind*2+1]);
}
}
int query(int ind, int l, int r, int ql, int qr){
if(l > r || l > qr || r < ql) return 0;
if(l >= ql && r <= qr) return tree[ind];
else{
int m = (l + r)/2;
return max(query(ind*2, l, m, ql, qr), query(ind*2+1, m+1, r, ql, qr));
}
}
};
int32_t main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int n, d;
cin>>n>>d;
vector<int> a(n);
vector<pair<int, int> > b(n);
for(int i = 0; i < n; i++){
cin>>a[i];
b[i] = {a[i], -i};
}
sort(b.begin(), b.end());
SEGTMN seg;
seg.init(n);
vector<int> lp(n);
for(int i = 0; i < n; i++){
int ind = -b[i].second;
lp[ind] = seg.query(1, 1, n, max(ind - d, 0LL) + 1, ind + 1);
lp[ind] = min(lp[ind], max(ind - d, 0LL));
seg.update(1, 1, n, ind + 1, lp[ind]);
}
SEGTMX segmx;
segmx.init(n);
vector<int> dp(n);
for(int i = 0; i < n; i++){
int ind = -b[i].second;
int l = lp[ind] + 1, r = ind + 1;
int val = segmx.query(1, 1, n, l, r);
dp[ind] = val + 1;
segmx.update(1, 1, n, ind + 1, val + 1);
}
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, dp[i]);
}
cout<<ans<<endl;
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... |