We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;typedeflonglongintl;intmain(){std::ios_base::sync_with_stdio(false);ln,r,i;cin>>n>>r;larr[n];map<int,int>count;map<int,int>track;for(i=0;i<n;i++){la;cin>>a;arr[i]=a;count[a]++;}lans=0;for(i=0;i<n;i++){//cout<<"\ncoubt of "<<arr[i]<<" is"<<count[arr[i]];count[arr[i]]--;// removig the one occurence of the element if(arr[i]%r==0){la=track[arr[i]/r];lb=count[arr[i]*r];ans=ans+a*b;}track[arr[i]]++;// adding the element to second map so that we could keep //the track on previous element like 1 3 9// we are simply storing 1 as a previous //element}cout<<ans;}Howaboutthiscode?
Count Triplets
You are viewing a single comment's thread. Return to all comments →