#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],nxt[N],prv[N],s,f;
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));
}void del(ll i){
nxt[prv[i]]=nxt[i];
prv[nxt[i]]=prv[i];
if(i==f)f=prv[i];
if(i==s)s=nxt[i];
}
bool get(){
ll cur=0;
for(ll i=s;i<=f;i=nxt[i])update(1,1,n,a[i],{0,0});
for(ll i=s;i<=f;i=nxt[i]){
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=f;i>=s;i=prv[i]){
if(dp[i].f==cur){
while(i!=0){
b.push_back(i);
update(1,1,n,a[i],{0,0});
del(i);
i=dp[i].s;
}
v.push_back(b);
break;
}
}
return 1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
s=1;
f=n;
for(ll i=1;i<=n;i++){
cin>>a[i];
nxt[i]=i+1;
prv[i]=i-1;
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... |