Submission #608993

#TimeUsernameProblemLanguageResultExecution timeMemory
608993kakayoshiFinancial Report (JOI21_financial)C++17
100 / 100
607 ms36028 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll,ll> pll; typedef pair<int, pair<int,int> > piii; typedef pair<pair<ll,ll> ,pair<ll, ll> > plll; typedef vector <ll> vi; #define forw(i,a,b) for (ll i=a;i<=(b);i++) #define forb(i,a,b) for (ll i=a;i>=(b);i--) #define fastIO {ios::sync_with_stdio(false); cin.tie(0); } #define fi first #define se second #define pu push #define puf push_front #define pb push_back #define pof pop_front #define pob pop_back #define fr front #define all(a) a.begin(),a.end() const ll oo=1e18; const ll mod=1e9+7; const int base=31; const ll maxN=3e5+5; const int tx[4]={0,1,0,-1}; const int ty[4]={1,0,-1,0}; const ll maxM=maxN*4+5; const ll block=500; struct segment { vector <ll> ans; vector <ll> date; vector <ll> lazy; segment(int n) { ans.assign(4*n+5,0); date.assign(4*n+5,0); lazy.assign(4*n+5,0); } void down(int id) { if (!lazy[id]) return; date[id*2]=lazy[id]; date[id*2+1]=lazy[id]; lazy[id*2]=lazy[id]; lazy[id*2+1]=lazy[id]; lazy[id]=0; return; } void update_ans(int id, int l, int r, int pos, ll val, ll time) { if (pos<l || r<pos) return; if (l==r) { if (l==pos) { date[id]=time; ans[id]=val; } return; } int mid=(l+r)/2; down(id); update_ans(id*2,l,mid,pos,val,time); update_ans(id*2+1,mid+1,r,pos,val,time); ans[id]=max(ans[id*2],ans[id*2+1]); if (!date[id*2]) date[id]=date[id*2+1]; else if (!date[id*2+1]) date[id]=date[id*2]; else date[id]=min(date[id*2],date[id*2+1]); return; } void update_date(int id, int l, int r, int u, int v, ll time) { if (v<l || r<u) return; if (u<=l && r<=v) { date[id]=time; lazy[id]=time; return; } down(id); int mid=(l+r)/2; update_date(id*2,l,mid,u,v,time); update_date(id*2+1,mid+1,r,u,v,time); if (!date[id*2]) date[id]=date[id*2+1]; else if (!date[id*2+1]) date[id]=date[id*2]; else date[id]=min(date[id*2],date[id*2+1]); return; } void erase(int id, int l, int r, int time) { if (!date[id]) return; if (date[id]>time || ans[id]==0) return; if (l==r) { ans[id]=0; date[id]=0; return; } int mid=(l+r)/2; down(id); erase(id*2,l,mid,time); erase(id*2+1,mid+1,r,time); if (!date[id*2]) date[id]=date[id*2+1]; else if (!date[id*2+1]) date[id]=date[id*2]; else date[id]=min(date[id*2],date[id*2+1]); ans[id]=max(ans[id*2],ans[id*2+1]); return; } ll get(int id,int l, int r, int u, int v) { if (v<l || r<u) return 0; if (u<=l && r<=v) return ans[id]; int mid=(l+r)/2; down(id); return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v)); } }; ll n,d,h[maxN],pos[maxN]; bool cmp(pii a, pii b) { if (a.fi!=b.fi) return a.fi<b.fi; return a.se>b.se; } void solve() { cin>>n>>d; segment seg(n); vector <pii> pend; forw(i,1,n) { cin>>h[i]; pend.pb({h[i],i}); } sort(all(pend),cmp); forw(i,0,n-1) pos[pend[i].se]=i+1; forw(i,1,n) { if (i-d-1>=1) seg.erase(1,1,n,i-d-1); int tmp=seg.get(1,1,n,1,pos[i])+1; //cout<<pos[i]<<" "<<i<<" "<<tmp<<endl; seg.update_ans(1,1,n,pos[i],tmp,i); seg.update_date(1,1,n,pos[i]+1,n,i); } cout<<seg.get(1,1,n,1,n); return; } int main() { ios::sync_with_stdio(0); cin.tie(0); //freopen("b.inp","r",stdin); //freopen("b.out","w",stdout); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...