Untitled
user_5379400
plain_text
a year ago
826 B
11
Indexable
#include<bits/stdc++.h>
using namespace std;
int n;
int a[2005];
map<int, vector<pair<int, int>>> mp;
void solve(int testcase){
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
mp.clear();
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
mp[a[i] * a[j]].push_back({i, j});
}
}
int ans = 0;
for (auto v : mp){
auto u = v.second;
sort(u.begin(), u.end());
int sz = u.size();
for (int i = 0; i < sz; i++){
for (int j = i - 1; j >= 0; j--){
if (u[j].first < u[i].first && u[j].second > u[i].second){
ans++;
}
}
}
}
cout << ans << '\n';
}
int main(){
//freopen("input.txt", "r", stdin);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) solve(i);
}Editor is loading...
Leave a Comment