Tranvick

Untitled

Nov 21st, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <algorithm>
  4. #define N 66666
  5.  
  6. using namespace std;
  7.  
  8. int a[N],n,kv,A[N],pw[31],ans,c[N];
  9.  
  10. int get(int x){
  11.     int l=0, r=kv-1;
  12.     while (l<r){
  13.         int m=(l+r)>>1;
  14.         if (x>a[m]) l=m+1;
  15.         else r=m;
  16.     }
  17.     if (a[l]==x) return c[l];
  18.     return 0;
  19. }
  20.  
  21. int main(){
  22.     freopen("input.txt","r",stdin);
  23.     freopen("output.txt","w",stdout);
  24.     scanf("%d",&n);
  25.     for (int i=0;i<n;i++) scanf("%d",&a[i]);
  26.     sort(a,a+n);   
  27.     kv=1;
  28.     c[0]=1;
  29.     for (int i=1;i<n;i++)
  30.         if (a[i] == a[kv-1]) c[kv-1]++;
  31.         else{
  32.             a[kv] = a[i];
  33.             c[kv++] = 1;
  34.         }
  35.     pw[0] = 1;
  36.     for (int i=1;i<30;i++) pw[i]=pw[i-1]<<1;
  37.     for (int i=0;i<kv;i++)
  38.         ans+=c[i]*(c[i]-1)/2;
  39.         for (int q=0;q<30;q++){
  40.             int t=a[i]^pw[q];
  41.             if (t<a[i]) ans+=c[i]*get(t);
  42.             for (int j=0;j<q;j++){
  43.                 t ^= pw[j];
  44.                 if (t<a[i]) ans+=c[i]*get(t);
  45.                 t^=pw[j];
  46.             }
  47.         }
  48.     }  
  49.     cout<<ans<<endl;
  50.     return 0;
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment