Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <algorithm>
- #define N 66666
- using namespace std;
- int a[N],n,kv,A[N],pw[31],ans,c[N];
- int get(int x){
- int l=0, r=kv-1;
- while (l<r){
- int m=(l+r)>>1;
- if (x>a[m]) l=m+1;
- else r=m;
- }
- if (a[l]==x) return c[l];
- return 0;
- }
- int main(){
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- scanf("%d",&n);
- for (int i=0;i<n;i++) scanf("%d",&a[i]);
- sort(a,a+n);
- kv=1;
- c[0]=1;
- for (int i=1;i<n;i++)
- if (a[i] == a[kv-1]) c[kv-1]++;
- else{
- a[kv] = a[i];
- c[kv++] = 1;
- }
- pw[0] = 1;
- for (int i=1;i<30;i++) pw[i]=pw[i-1]<<1;
- for (int i=0;i<kv;i++)
- ans+=c[i]*(c[i]-1)/2;
- for (int q=0;q<30;q++){
- int t=a[i]^pw[q];
- if (t<a[i]) ans+=c[i]*get(t);
- for (int j=0;j<q;j++){
- t ^= pw[j];
- if (t<a[i]) ans+=c[i]*get(t);
- t^=pw[j];
- }
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment