#include <iostream>
using namespace std;
int a[20];
int dp[1<<20][20];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
dp[a[i]][0] = a[i];
}
int cnt = 0;
while( (1<<cnt) <= n ) cnt ++;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= cnt; j++)
{
if( i & (1<<(j-1)) ) dp[i][j] = dp[i][j-1] + dp[i^(1<<(j-1))][j-1];
else dp[i][j] = dp[i][j-1];
}
}
for (int i = 1; i <= n; i++)
{
cout << dp[i][cnt] << '\n';
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-11301.html