#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);
bool ok = 1; int prv = -1;
for (int i = 0; i < len; i++){
while (!hist[i].empty() && hist[i].back().first <= prv) hist[i].pop_back();
if (hist[i].empty()){
ok = 0; break;
}
temp[i] = hist[i].back().second; prv = hist[i].back().first;
hist[i].pop_back();
}
if (!ok) break;
ans.push_back(temp);
}
cout << ans.size() << ' ' << len << '\n';
for (auto v : ans){
for (int x : v) cout << x << ' ';
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... |