Harman5007

Untitled

Apr 15th, 2020
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. long countTriplets(vector<long> arr, long r) {
  2.  
  3. unordered_map<long,long> rm;
  4. unordered_map<long,long> lm;
  5.  
  6. int i;
  7. long sum=0;
  8.  
  9. for(i=0;i<arr.size();i++)
  10. {
  11. rm[arr[i]]++;
  12. }
  13.  
  14. for(i=0;i<arr.size();i++)
  15. {
  16. rm[arr[i]]--;
  17. if(arr[i]%r==0)
  18. {
  19. sum += (lm[arr[i]/r]) * (rm[arr[i]*r]);
  20. }
  21. lm[arr[i]]++;
  22. }
  23.  
  24. return sum;
  25. }
Add Comment
Please, Sign In to add comment