QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697563 | #8077. Alice and Bob | SunsetGlow95 | RE | 0ms | 0kb | C++14 | 1.6kb | 2024-11-01 14:52:50 | 2024-11-01 14:52:51 |
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MXN = 500005;
const int MXD = 60;
int T, N, ns;
ll arr[MXN], ans;
pair<ll, int> num[MXN];
ll read() {
ll x(0);
int c(getchar());
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + (c - '0'), c = getchar();
return x;
}
void write(ll x) {
static char buf[21];
if (!x) {
putchar('0');
return;
}
int d(0);
while (x) buf[d++] = x % 10 + '0', x /= 10;
while (d) putchar(buf[--d]);
}
void calc(int l, int r, int d) {
if (r - l <= 1 || d == MXD) return;
int m(r);
ll c01(0), c02(0), c11(0), c12(0);
for (int i(l); i != m; ++i) {
if ((num[i].first >> d) & 1) {
c11 += num[i].second, c12 += num[i].second * 1LL * (num[i].second - 1) / 2;
swap(num[i--], num[--m]);
} else {
c01 += num[i].second, c02 += num[i].second * 1LL * (num[i].second - 1) / 2;
}
}
if (d % 2 == 0) ans += c01 * c12 + c02 * c11;
calc(l, m, d + 1), calc(m, r, d + 1);
}
int main() {
freopen("game.in", "r", stdin);
freopen("game.out", "w", stdout);
T = read();
while (T--) {
N = read();
for (int i(0); i != N; ++i) arr[i] = read();
sort(arr, arr + N);
ns = 0;
for (int i(0); i != N; ++i) {
if (ns && arr[i] == num[ns - 1].first) ++num[ns - 1].second;
else num[ns++] = make_pair(arr[i], 1);
}
ans = 0;
for (int i(0); i != ns; ++i) {
ans += num[i].second * 1LL * (num[i].second - 1) * (num[i].second - 2) / 6;
}
calc(0, ns, 0);
write(N * 1LL * (N - 1) * (N - 2) / 6 - ans), putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 4 2 0 2 3 3 2 2 3 3 0 2 3