#include <bits/stdc++.h>
//qwerty47924692
using namespace std;
using ll = int;
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;
set<ll>s;
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:s)update(1,1,n,a[i],{0,0});
for(ll i:s){
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;
vector<ll>del;
for(auto it=s.end();it!=s.begin();it--){
auto i=*(--it);
if(dp[i].f==cur){
while(i!=0){
b.push_back(i);
update(1,1,n,a[i],{0,0});
del.push_back(i);
i=dp[i].s;
}
for(ll i:del)s.erase(i);
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];
s.insert(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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |