Harman5007

Untitled

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