提交时间:2022-08-09 11:33:24

运行 ID: 55124

#include <bits/stdc++.h> using namespace std; #define ll long long int n; ll a[200005]; int sl[25]; int maxj = 0; int main() { // freopen("basis4.in", "r", stdin); // freopen("basis.out", "w", stdout); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); int j; for (j = 0; (a[i] >> j) > 0; j++) { sl[j] += (a[i] >> j) & 1; } maxj = max(maxj, j); } // sort(a + 1, a + n + 1); // for (int i = 1; i <= n; i++) { //// int j = i + 1; //// if (j > n) break; // for (int j = 1; j <= n; j++) { // ll x, y; // x = a[i] & a[j], y = a[i] | a[j]; // a[i] = x, a[j] = y; // } // // } // for (int i = 1; i <= n; i++) { // printf("%lld ", a[i]); // } ll ans = 0; for (int i = 1; i <= n; i++) { a[i] = 0; for (int j = 0; j < maxj; j++) { if (sl[j]) { sl[j]--; a[i] |= (1 << j); } } ans += a[i] * a[i]; } printf("%lld\n", ans); return 0; } /* 8 114514 1919810 545 343 42985 11597 89799 314519 */