#include<bits/stdc++.h> using namespace std; const int INF = 1e9; int n; vector<int> t; vector<pair<int,int> > res; vector<int> S; pair<int,int> merge(pair<int,int>& a, int b){ if(a.first != b) return (a.first < b ? a : make_pair(b,1)); return {a.first, a.second+1}; } int calc(int p){ int res = 0; for(int i : S) res += (i > p ? 1 : 0); return res; } void solve(int x=0, int p=0){ if(x == n){ res[S.size()] = merge(res[S.size()], p); return; } solve(x+1,p); p += calc(t[x]); S.push_back(t[x]); solve(x+1,p); S.pop_back(); } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; t.resize(n); for(int& i : t) cin >> i; res.assign(n+1,{INF,INF}); solve(); for(int i=1;i<=n;i++) cout << res[i].first << " " << res[i].second << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include<bits/stdc++.h> using namespace std; const int INF = 1e9; int n; vector<int> t; vector<pair<int,int> > res; vector<int> S; pair<int,int> merge(pair<int,int>& a, int b){ if(a.first != b) return (a.first < b ? a : make_pair(b,1)); return {a.first, a.second+1}; } int calc(int p){ int res = 0; for(int i : S) res += (i > p ? 1 : 0); return res; } void solve(int x=0, int p=0){ if(x == n){ res[S.size()] = merge(res[S.size()], p); return; } solve(x+1,p); p += calc(t[x]); S.push_back(t[x]); solve(x+1,p); S.pop_back(); } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; t.resize(n); for(int& i : t) cin >> i; res.assign(n+1,{INF,INF}); solve(); for(int i=1;i<=n;i++) cout << res[i].first << " " << res[i].second << "\n"; return 0; } |