#include <bits/stdc++.h> using namespace std; #define int long long pair <int,int> T[50]; int ALL = 0; int ile_el = 0, ile_inw = 0; void rek(int x, vector <int> &a){ if(x == a.size()){ if(T[ile_el].first == -1 || T[ile_el].first > ile_inw){ T[ile_el] = {ile_inw,1}; } else if(T[ile_el].first == ile_inw){ T[ile_el].second++; } return; } rek(x+1,a); ++ile_el; int u = 1LL << a[x]; int u2 = (1LL << (a[x] + 1)); u2 -= 1; u2 = ~u2; int r = __builtin_popcountl(u2&ALL); ile_inw += r; ALL |= u; rek(x+1,a); ALL ^= u; ile_inw -= r; --ile_el; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector <int > a(n); for(int i = 0; i < n; ++i){ cin >> a[i]; --a[i]; } for(int i = 0; i < 50 ;++i){ T[i] = {-1,0}; } rek(0,a); for(int i = 1; i <= n; ++i){ cout << T[i].first << ' ' << T[i].second << '\n'; } }
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 | #include <bits/stdc++.h> using namespace std; #define int long long pair <int,int> T[50]; int ALL = 0; int ile_el = 0, ile_inw = 0; void rek(int x, vector <int> &a){ if(x == a.size()){ if(T[ile_el].first == -1 || T[ile_el].first > ile_inw){ T[ile_el] = {ile_inw,1}; } else if(T[ile_el].first == ile_inw){ T[ile_el].second++; } return; } rek(x+1,a); ++ile_el; int u = 1LL << a[x]; int u2 = (1LL << (a[x] + 1)); u2 -= 1; u2 = ~u2; int r = __builtin_popcountl(u2&ALL); ile_inw += r; ALL |= u; rek(x+1,a); ALL ^= u; ile_inw -= r; --ile_el; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector <int > a(n); for(int i = 0; i < n; ++i){ cin >> a[i]; --a[i]; } for(int i = 0; i < 50 ;++i){ T[i] = {-1,0}; } rek(0,a); for(int i = 1; i <= n; ++i){ cout << T[i].first << ' ' << T[i].second << '\n'; } } |