#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin>>n;
vi a(n);
F0R(i,n)cin>>a[i];
map<int,set<pi>> mp;
vi _dp;
F0R(i,n){
int pos=upper_bound(_dp.begin(),_dp.end(),a[i]) - _dp.begin();
if(pos==sz(_dp)) _dp.pb(a[i]);
else _dp[pos]=a[i];
mp[pos+1].insert({a[i],i});
}
int m=sz(_dp);
vector<vi> ans;
while(1){
int i=1;
vi tmp;
while(i<=m){
if(mp[i].empty()){
break;
}
auto it=mp[i].rbegin();
if(it->f>(sz(tmp)? a[tmp.back()]: 0)){
tmp.pb(it->s);
i++;
}
else if(i){
mp[i-1].erase(mp[i-1].find({a[tmp.back()],tmp.back()}));
tmp.pop_back();
i--;
}
else{
break;
}
}
if(sz(tmp)!=m){
break;
}
else{
ans.pb(tmp);
FORd(i,1,m+1){
mp[i].erase(mp[i].find({a[tmp.back()],tmp.back()}));
tmp.pop_back();
}
}
}
cout<<sz(ans)<<" "<<m<<nl;
trav(i,ans){
trav(j,i)cout<<j+1<<" ";
cout<<nl;
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
// cin >> TC;
while(TC--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |