Submission #862316

#TimeUsernameProblemLanguageResultExecution timeMemory
862316imarnStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
224 ms33804 KiB
#include "bits/stdc++.h" #define f first #define s second #define ll long long #define pb push_back #define pii pair<ll,ll> using namespace std; const int N=2e5+5; unordered_map<int,vector<int>>dp; ll t[4*N],lz[4*N]; void push(int i,int l,int r){ if(lz[i]){ t[i]=lz[i]; if(l<r){ lz[2*i]=lz[i]; lz[2*i+1]=lz[i]; } }lz[i]=0; } void upd(int i,int l,int r,int tl,int tr,int v){ push(i,l,r); if(r<tl||l>tr)return; if(r<=tr&&l>=tl){ lz[i]=v;push(i,l,r);return; }int m=(l+r)>>1; upd(2*i,l,m,tl,tr,v); upd(2*i+1,m+1,r,tl,tr,v); t[i]=max(t[2*i],t[2*i+1]); } int qr(int i,int l,int r,int idx){ push(i,l,r); if(r<idx||l>idx)return 0; if(l==r)return t[i]; int m=(l+r)>>1; return max(qr(2*i,l,m,idx),qr(2*i+1,m+1,r,idx)); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n; int a[n+1]; for(int i=1;i<=n;i++)cin>>a[i]; dp[a[1]].pb(1);upd(1,1,n,1,1,a[1]); for(int i=2;i<=n;i++){ if(dp.find(a[i])!=dp.end()){ while(!dp[a[i]].empty()&&qr(1,1,n,dp[a[i]].back())!=a[i])dp[a[i]].pop_back(); if(!dp[a[i]].empty()){ upd(1,1,n,dp[a[i]].back(),i-1,a[i]); } }upd(1,1,n,i,i,a[i]); dp[a[i]].pb(i); } for(int i=1;i<=n;i++)cout<<qr(1,1,n,i)<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...