Submission #916444

#TimeUsernameProblemLanguageResultExecution timeMemory
916444amirhoseinfar1385Financial Report (JOI21_financial)C++17
53 / 100
4054 ms23380 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=300000+10; int all[maxn],n,d,kaf=(1<<19); vector<pair<int,int>>v; bool cmp(pair<int,int>a,pair<int,int>b){ if(a.first==b.first){ return a.second>b.second; } return a.first<b.first; } struct segmenta{ long long seg[(1<<20)]; segmenta(){ for(int i=0;i<(1<<20);i++){ seg[i]=1; } } void upd(int i,int l,int r,int tl,int tr){ if(l>r||l>tr||r<tl||tl>tr||seg[i]==0){ return ; } if(l>=tl&&r<=tr){ seg[i]=0; return ; } int m=(l+r)>>1; upd((i<<1),l,m,tl,tr); upd((i<<1)^1,m+1,r,tl,tr); return ; } int pors(int i,int l,int r,int tl,int tr){ if(l>r||l>tr||r<tl||tl>tr||seg[i]==0){ return 0; } if(l==r){ return l; } int m=(l+r)>>1; int ret=pors((i<<1)^1,m+1,r,tl,tr); if(ret==0){ return pors((i<<1),l,m,tl,tr); } return ret; } }seg1; struct segment{ long long seg[(1<<20)]; void ins(int i,long long w){ while(i>0){ seg[i]=max(seg[i],w); i>>=1; } } int pors(int i,int l,int r,int tl,int tr){ if(l>r||l>tr||r<tl||tl>tr){ return 0; } if(l>=tl&&r<=tr){ return seg[i]; } int m=(l+r)>>1; return max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr)); } }seg; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>d; for(int i=1;i<=n;i++){ cin>>all[i]; v.push_back(make_pair(all[i],i)); } sort(v.begin(),v.end(),cmp); for(int i=0;i<n;i++){ int ind=v[i].second; seg1.upd(1,0,kaf-1,ind-d+1,ind); int l=seg1.pors(1,0,kaf-1,0,ind-1); int res=seg.pors(1,0,kaf-1,l,ind-1)+1; seg.ins(ind+kaf,res); } // for(int i=1;i<=n;i++){ // cout<<i<<" "<<seg.pors(1,0,kaf-1,i,i)<<endl; // } cout<<seg.pors(1,0,kaf-1,1,n)<<endl; }
#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...