forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0982.cpp
More file actions
33 lines (31 loc) · 674 Bytes
/
0982.cpp
File metadata and controls
33 lines (31 loc) · 674 Bytes
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
#include <vector>
#include <iostream>
using namespace std;
static int x = [](){std::ios::sync_with_stdio(false);cin.tie(0);return 0;}();
class Solution
{
public:
int countTriplets(vector<int>& A)
{
int arr[1<<16] = {};
int all = (1<<16) - 1;
for(int a : A)
{
int k = all ^ a;
for(int i=k; ; i = (i-1) & k)
{
arr[i ^ a]++;
if(i == 0) break;
}
}
int res = 0;
for (int a : A)
{
for (int b : A)
{
res += arr[all ^ (a&b)];
}
}
return res;
}
};