rakcode1998

Untitled

Apr 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6.  
  7. typedef long long ll;
  8. typedef long double ld;
  9. typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>Set;
  10. typedef tree<ll,ll,less<ll>,rb_tree_tag,tree_order_statistics_node_update> Map;
  11.  
  12. #define pb push_back
  13. #define mp make_pair
  14. #define mod 1000000007
  15. #define fi first
  16. #define se second
  17. #define pll pair<ll,ll>
  18. #define ook order_of_key
  19. #define findby find_by_order
  20. #define pii pair<ll,ll>
  21. #define gcd(a,b) __gcd(a,b)
  22. #define rep(i,n) for(ll i=0;i<n;i++)
  23. #define reps(i,a,b) for(ll i=a;i<=b;i++)
  24.  
  25. template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
  26. template<typename X> inline X sqr(const X& a) { return (a * a); }
  27.  
  28. const ld EPS = ld(1e-9);
  29. const ld PI = ld(3.141592653589);
  30.  
  31. int n;
  32. int k;
  33. map<ll,ll>check;
  34.  
  35. class Task
  36. {
  37. public:
  38.      void solve(istream& in,ostream& out)
  39.      {
  40.            int c;
  41.            in >> n >> k;
  42.            rep(i,n)
  43.            {
  44.                  in >> c;
  45.                  check[c] ++;
  46.            }
  47.  
  48.            ll res = 0;
  49.  
  50.            if (k!=0)
  51.            {
  52.                  rep(i,10003)
  53.                  {
  54.                       for (int j=i+1;j<10004 ;j++)
  55.                       {
  56.                             if (__builtin_popcount(i^j) == k)
  57.                             {
  58.                                  res += (ll)(check[i])*(ll)(check[j]);
  59.                             }
  60.                       }
  61.                  }
  62.            }
  63.            else
  64.            {
  65.                  for (auto j=check.begin();j!=check.end();j++)
  66.                  {
  67.                       ll c = (*j).se;
  68.                       res += (c)*(c-1)/2;
  69.                  }
  70.            }
  71.  
  72.            out << res << endl;
  73.      }
  74. };
  75.  
  76.  
  77. int main()
  78. {
  79.     ios_base::sync_with_stdio(false);
  80.     cin.tie(NULL);
  81.     cout.tie(NULL);
  82.     Task solver;
  83.     std::istream& in(std::cin);
  84.     std::ostream& out(std::cout);
  85.     solver.solve(in,out);
  86.     out.flush();
  87.  
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment