/
h.cpp
60 lines (60 loc) · 985 Bytes
/
h.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int maxn = 250000;
int h[maxn + 5], data[maxn + 5], ret[maxn + 5];
inline bool reachable(int a, int b)
{
int c = a ^ b;
int cnt = 0;
while(c)
{
if (c & 1)
{
cnt ++;
if (cnt > 2)return false;
}
c >>= 1;
}
return true;
}
int main()
{
int t, n = 0;
while(1)
{
scanf("%d", &t);
if (t == -1)
break;
data[n++] = t;
}
for (int i = n - 1; i >= 0; i--)
{
int ans = h[data[i]];
for (int j1 = 1; j1 <= maxn; j1 <<= 1)
{
int t = data[i] ^ j1;
if (t <= maxn)
ans += h[t];
for (int j2 = (j1 << 1); j2 <= maxn; j2 <<= 1)
{
t = data[i] ^ j1 ^ j2;
if (t <= maxn)
ans += h[t];
}
}
// printf("%d:%d\n", data[i], ans);
ret[i] = ans;
h[data[i]] += 1;
}
for (int i = 0; i < n; i++)
printf("%d:%d\n", data[i], ret[i]);
return 0;
}