QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#319086 | #8077. Alice and Bob | PetroTarnavskyi# | TL | 0ms | 3848kb | C++20 | 1.2kb | 2024-02-01 19:36:52 | 2024-02-01 19:36:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int LOG = 62;
void solve()
{
LL n;
cin >> n;
map<LL, LL> cnt;
vector<LL> a(n);
FOR(i, 0, n)
{
cin >> a[i];
cnt[a[i]]++;
}
map<LL, LL> CNT[LOG];
FOR(i, 0, n)
{
FOR(k, 0, LOG)
{
if(k % 2 == 1)
continue;
LL val = a[i] & ((1LL << (k + 1)) - 1);
CNT[k][val]++;
}
}
LL ans = n * (n - 1) * (n - 2) / 6;
for(auto [y, num] : cnt)
{
LL cur = num * (num - 1) / 2;
LL sum = 0;
FOR(k, 0, LOG)
{
if(k % 2 == 1)
continue;
LL val = y & ((1LL << (k + 1)) - 1);
val ^= (1LL << k);
sum += CNT[k][val];
}
ans -= cur * sum;
ans -= num * (num - 1) * (num - 2) / 6;
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
3 4 2 0 2 3 3 2 2 3 3 0 2 3
output:
3 0 1
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
1000000 3 63 98 95 3 61 38 97 3 7 73 98 3 1 10 91 3 94 31 99 3 96 54 97 3 14 44 99 3 81 51 97 3 96 95 92 3 35 90 98 3 7 39 96 3 71 8 96 3 36 35 99 3 82 52 96 3 89 53 99 3 76 85 95 3 80 34 91 3 9 13 99 3 12 17 94 3 40 4 95 3 57 5 93 3 47 69 93 3 23 0 94 3 62 44 97 3 7 4 99 3 21 97 99 3 41 3 99 3 36 9...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...