Advertisement
maycod23

practise_contest_2_q_3

Mar 6th, 2022
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6.     ll t; cin >> t;
  7.     while (t--)
  8.     {
  9.         ll n, x, ans = 0; cin >> n >> x;
  10.         vector<ll> v(n);
  11.         map<ll, ll> m;
  12.         for (ll i = 0; i < n; i++)
  13.         {
  14.             cin >> v[i];
  15.             m[v[i]]++;
  16.         }
  17.         sort(v.begin(), v.end());
  18.         for (ll i = 0; i < n; i++)
  19.         {
  20.             if (m[v[i]] == 0) continue;//already taken
  21.             else//not taken
  22.             {
  23.                 ll temp = (x * v[i]);
  24.                 m[v[i]]--;//mark v[i] as taken
  25.  
  26.                 //we need to check whether temp is present in the map or not
  27.                 if (m.find(temp) != m.end())
  28.                 {
  29.                     if (m[temp] >= 1) m[temp]--;//taken
  30.                     else ans++;
  31.                 }
  32.                 else
  33.                 {
  34.                     ans++;
  35.                 }
  36.             }
  37.         }
  38.  
  39.         // t.c>O(n*log(number of keys))>O(nlogn).
  40.         cout << ans << endl;
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement