Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "GEN"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- int n, a[N], cnt[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- cin >> a[i];
- }
- // Kiểm tra liệu số x có bao nhiêu bit mở
- bool OnlyOneBit(int x)
- {
- // Ở đây (x & -x) là lũy thừa lớn nhất của 2 là ước của x
- // x có một bit mở nếu và chỉ nếu x là lũy thừa của 2
- return x == (x & -x);
- }
- void Solve()
- {
- ll ans(0);
- for (int i = 1; i <= n; ++i)
- ++cnt[a[i]]; // Đếm phân phối
- for (int x = 1; x <= 1000; ++x)
- {
- ans += 1ll * cnt[x] * (cnt[x] - 1) / 2; // Bài toán số 1
- for (int y = x + 1; y <= 1000; ++y)
- if (OnlyOneBit(x ^ y))
- ans += cnt[x] * cnt[y]; // Bài toán số 2
- // Hai bit giống nhau xor sẽ ra 0
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Add Comment
Please, Sign In to add comment