Submission #967879

#TimeUsernameProblemLanguageResultExecution timeMemory
967879vjudge1Financial Report (JOI21_financial)C++17
100 / 100
503 ms27648 KiB
#include <bits/stdc++.h> #define getbit(i, j) ((i >> j) & 1) #define maxn 300005 #define name "main" using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long GetRandom(long long l, long long r) { return uniform_int_distribution<long long> (l, r)(rng); } int n,d,a[maxn],st[maxn*4],dp[maxn],dem[maxn],sl,res,lazy[maxn*4],mod=-1e9; pair<int,int> b[maxn],tt[maxn*4]; void build(int id,int l,int r) { if(l>r) return; if(l==r) { st[id]=mod; tt[id]={1e9,0}; return; } int mid=(l+r)/2; build(id*2,l,mid); build(id*2+1,mid+1,r); st[id]=-1e9; tt[id]={1e9,0}; } void updatest(int id,int l,int r,int vt,int val) { if(l>vt||r<vt) return; if(l==r) { st[id]=max(st[id],val); if(val==0) st[id]=0; return; } int mid=(l+r)/2; updatest(id*2,l,mid,vt,val); updatest(id*2+1,mid+1,r,vt,val); st[id]=max(st[id*2],st[id*2+1]); } int get(int id,int l,int r,int d,int c) { if(l>c||r<d) return 0; if(l>=d&&r<=c) return st[id]; int mid=(l+r)/2; return max(get(id*2,l,mid,d,c),get(id*2+1,mid+1,r,d,c)); } void lazy1(int id) { int val=lazy[id]; lazy[id]=0; lazy[id*2]=max(lazy[id*2],val); lazy[id*2+1]=max(lazy[id*2+1],val); if(tt[id*2].first!=1e9) tt[id*2].first=max(tt[id*2].first,val); if(tt[id*2+1].first!=1e9) tt[id*2+1].first=max(tt[id*2+1].first,val); } void updatett(int id,int l,int r,int d,int c,int val) { if(l>c||r<d) return; if(l>=d&&r<=c) { if(val==0) { tt[id].first=1e9; tt[id].second=0; return; } else if(d==c) { tt[id].first=val; tt[id].second=l; return; } else { if(tt[id].first==1e9) return; tt[id].first=max(tt[id].first,val); lazy[id]=max(lazy[id],val); return; } } int mid=(l+r)/2; lazy1(id); updatett(id*2,l,mid,d,c,val); updatett(id*2+1,mid+1,r,d,c,val); tt[id]=tt[id*2]; if(tt[id].first>tt[id*2+1].first) tt[id]=tt[id*2+1]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // if(fopen(name".inp","r")) // { // freopen(name".inp","r",stdin); // freopen(name".out","w",stdout); // } cin >> n >> d; for(int i=1;i<=n;i++) { cin >> a[i]; b[i]={a[i],i}; } sort(b+1,b+n+1); sl=1; a[b[1].second]=sl; for(int i=2;i<=n;i++) { if(b[i].first>b[i-1].first) sl++; a[b[i].second]=sl; } build(1,1,sl); for(int i=1;i<=n;i++) { while(i-tt[1].first>d) { int val=tt[1].second; // cout<<val<<' '<<tt[1].first<<' '<<i<<'\n';; updatest(1,1,sl,val,0); updatett(1,1,sl,val,val,0); } dp[i]=max(1,get(1,1,sl,1,a[i]-1)+1); updatest(1,1,sl,a[i],dp[i]); updatett(1,1,sl,a[i],a[i],i); updatett(1,1,sl,a[i]+1,sl,i); res=max(res,dp[i]); } cout<<res; }
#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...