제출 #1198059

#제출 시각아이디문제언어결과실행 시간메모리
1198059brover29Volontiranje (COCI21_volontiranje)C++17
50 / 110
1098 ms56000 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = long long; const ll N=1e6+29; const string br="617283"; #define sz(a)(ll)a.size() #define f first #define s second ll n,k,a[N]; pair<ll,ll>st[4*N],dp[N]; vector<vector<ll>>v; ll mx=0; void update(ll v,ll l,ll r,ll pos,pair<ll,ll> x){ if(l==r){ st[v]=x; return; } ll mid=(r+l)>>1; if(pos<=mid)update(v*2,l,mid,pos,x); else update(v*2+1,mid+1,r,pos,x); st[v]=max(st[v*2],st[v*2+1]); } pair<ll,ll> get(ll v,ll l,ll r,ll x,ll y){ if(l>y||x>r||x>y)return {0,0}; if(x<=l&&r<=y)return st[v]; ll mid=(r+l)>>1; return max(get(v*2,l,mid,x,y),get(v*2+1,mid+1,r,x,y)); } bool get(){ ll cur=0; for(ll i=1;i<=n;i++)update(1,1,n,i,{0,0}); for(ll i=1;i<=n;i++){ dp[i].f=-1e18; if(a[i]==-1e18)continue; dp[i]=get(1,1,n,1,a[i]-1); // cout<<dp[i].f<<' '; dp[i].f++; update(1,1,n,a[i],{dp[i].f,i}); cur=max(cur,dp[i].f); }vector<ll>b; if(cur!=mx)return 0; for(ll i=n;i>=1;i--){ if(dp[i].f==cur){ while(i!=0){ b.push_back(i); a[i]=-1e18; i=dp[i].s; } v.push_back(b); break; } } return 1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(ll i=1;i<=n;i++){ cin>>a[i]; dp[i]=get(1,1,n,1,a[i]-1); dp[i].f++; update(1,1,n,a[i],{dp[i].f,i}); mx=max(mx,dp[i].f); } while(get()){ continue; }cout<<v.size()<<' '<<mx<<'\n'; for(auto vv:v){ reverse(vv.begin(),vv.end()); for(ll i:vv){ cout<<i<<' '; } cout<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...