#include<bits/stdc++.h>
using namespace std;
#define NAME "VOLUNTEER"
#define nl '\n'
#define allofa(x,sz) x,x+sz+1
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,val) memset(x,val,sizeof(x))
#define couf(x) cout << fixed << setprecision(x)
template<class T> T Abs(T &x) {return (x>=0 ? x : -x);};
template<class X,class Y> bool minimize(X &a, Y b){if(a>b) {a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b) {a=b;return true;}return false;};
typedef long long ll;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e15;
const int INF = (int)1e9;
const int MAXN = (int)1e6+5;
vector<int> e[MAXN];
int org[MAXN],a[MAXN];
ll dp[MAXN];
int n;
void ccps() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    if(fopen(NAME".inp","r")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
}
struct FenwickTree {
    int n;
    vector<ll> fen;
    FenwickTree(int N = 0) {
        n=N;
        if(n>0) {
            fen.assign(n+1,0);
        }
    }
    void update(int node, ll val) {
        while(node<=n) {
            maximize(fen[node],val);
            node+=(node & -node);
        }
    }
    ll getVal(int node) {
        ll res = 0;
        while(node>0) {
            maximize(res,fen[node]);
            node-=(node & -node);
        }
        return res;
    }
} bit;
signed main() {
    ccps();
    cin >> n;
    vector<int> comp;
    fill(allofa(dp,n+1),1);
    for (int i = 1; i<=n; i++) {
        cin >> org[i];
        comp.push_back(org[i]);
    }
    sort(allof(comp));
    comp.resize(unique(allof(comp))-comp.begin());
    bit = FenwickTree((int)comp.size());
    for (int i = 1; i<=n; i++) {
        a[i] = lower_bound(allof(comp),org[i])-comp.begin()+1;
    }
    ll lisLen = 0;
    for (int i = 1; i<=n; i++) {
        dp[i] = bit.getVal(a[i]-1)+1;
        e[dp[i]].push_back(i);
        bit.update(a[i],dp[i]);
        maximize(lisLen,dp[i]);
    }
    for (int i = 0; i<=lisLen; i++) {
        reverse(allof(e[i]));
    }
    vector<vector<int>> res;
    stack<int> st;
    while(true) {
        if(st.empty()) {
            if(e[1].empty()) break;
            st.push(e[1].back());
            e[1].pop_back();
        }
        else if((int)st.size()==lisLen) {
            vector<int> par;
            while(!st.empty()) {
                par.push_back(st.top());
                st.pop();
            }
            reverse(allof(par));
            res.push_back(par);
        }
        else {
            int curLen = (int)st.size();
            int curID = st.top();
            while(!e[curLen+1].empty() and e[curLen+1].back()<curID) e[curLen+1].pop_back();
            if(e[curLen+1].empty() or a[curID]>a[e[curLen+1].back()]) st.pop();
            else {
                st.push(e[curLen+1].back());
                e[curLen+1].pop_back();
            }
        }
    }
    cout << (int)res.size() << " " << lisLen << nl;
    for (vector<int> v : res) {
        for (int x : v) cout << x << " ";
        cout << nl;
    }
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void ccps()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |