You are viewing a single comment's thread. Return to all comments →
You can use the sweep order to handle the problem well. Neat question.
#include <iostream> #include <vector> #include <map> using namespace std; long long n; long long r; int main() { cin>>n>>r; vector<long long> v; v.resize(n); map<long long, long long> c; map<long long, long long> s; long long tot = 0; for (int i = 0; i < n; i++) cin>>v[i]; for (int i = n-1; i >= 0; i--) { tot += s[r*v[i]]; s[v[i]] += c[r*v[i]]; c[v[i]]++; } cout<<tot<<'\n'; }
Seems like cookies are disabled on this browser, please enable them to open this website
Count Triplets
You are viewing a single comment's thread. Return to all comments →
You can use the sweep order to handle the problem well. Neat question.