#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int nums; cin >> nums;
	vector<int> inc;
	vector<vector<pair<int, int>>> hist;
	for (int i = 1; i <= nums; i++){
		int x; cin >> x;
		if (inc.empty() || x > inc.back()){
			inc.push_back(x);
			hist.push_back({}); hist.back().push_back({x, i});
		}
		else{
			auto it = lower_bound(inc.begin(), inc.end(), x + 1);
			int id = it - inc.begin();
			*it = x;
			hist[id].push_back({x, i});
		}
	}
	vector<vector<int>> ans;
	int len = inc.size();
	while (1){
		vector<int> temp(len + 1), vals(len + 1);
		int ok = 1; temp[len] = vals[len] = nums + 1;
		for (int i = len - 1; i >= 0; i--){
			while (!hist[i].empty() && hist[i].back().second > temp[i + 1]) hist[i].pop_back();
			if (hist[i].empty()){
				ok = 0; break;
			}
			if (hist[i].back().first > vals[i + 1]){
				i += 2; continue;
			}
			temp[i] = hist[i].back().second; vals[i] = hist[i].back().first;
			hist[i].pop_back();
		}
		if (ok == 0) break;
		ans.push_back(temp);
	}
	cout << ans.size() << ' ' << len << '\n';
	for (auto v : ans){
		for (int i = 0; i < len; i++) cout << v[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... |