This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 300005
ll n,d;
ll a[maxn];
ll t[2*maxn],t2[2*maxn],lazy[2*maxn],ls[2*maxn],rs[2*maxn],tsz = 0,root = 0;
void init(ll &v,ll tl,ll tr){
v = ++tsz;
if(tl==tr) return;
ll mid = (tl+tr)/2;
init(ls[v],tl,mid);
init(rs[v],mid+1,tr);
}
void upd(ll v,ll tl,ll tr,ll i,ll x){
if(tl==tr){t[v] = x;return;}
ll mid = (tl+tr)/2;
if(i<=mid) upd(ls[v],tl,mid,i,x);
else upd(rs[v],mid+1,tr,i,x);
t[v] = max(t[ls[v]],t[rs[v]]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
if(tr<l||tl>r||tl>tr) return 0;
if(l<=tl&&tr<=r) return t[v];
ll mid = (tl+tr)/2;
return max(get(ls[v],tl,mid,l,r),get(rs[v],mid+1,tr,l,r));
}
void upd(ll v,ll x){
t2[v] = x;
lazy[v] = x;
}
void push(ll v){
if(lazy[v]){
upd(ls[v],lazy[v]);
upd(rs[v],lazy[v]);
}
lazy[v] = 0;
}
void upd(ll v,ll tl,ll tr,ll l,ll r,ll x){
if(r<tl||l>tr||tl>tr) return;
if(l<=tl&&tr<=r){upd(v,x);return;}
push(v);
ll mid = (tl+tr)/2;
upd(ls[v],tl,mid,l,r,x);
upd(rs[v],mid+1,tr,l,r,x);
t2[v] = min(t2[ls[v]],t2[rs[v]]);
}
ll get(ll v,ll tl,ll tr,ll x){
if(tl==tr) return tl;
push(v);
ll mid = (tl+tr)/2;
if(t2[rs[v]]<x) return get(rs[v],mid+1,tr,x);
return get(ls[v],tl,mid,x);
}
void tc(){
cin >> n >> d;
for(ll i = 1;i<=n;i++) cin >> a[i];
{
set<ll> s;
ll it = 0;
map<ll,ll> mp;
for(ll i = 1;i<=n;i++) s.insert(a[i]);
for(ll x : s) mp[x] = ++it;
for(ll i = 1;i<=n;i++) a[i] = mp[a[i]];
}
init(root,1,n);
for(ll i = 1;i<=n;i++){
ll k = get(root,1,n,i-d)+1;
if(t2[root]>=i-d) k = 1;
ll x = a[i];
ll y = max(get(root,1,n,x,x),1LL);
if(x>k) y = max(y,get(root,1,n,k,x-1)+1);
upd(root,1,n,x,y);
upd(root,1,n,x,n,i);
}
cout<<t[root]<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
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... |