I have seen the solutions of other people after continuous failing of my code. It seems that everyone has used an algorithm similar to mine, but still my code keeps failing on the last test case.
include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
int tot=(n*(n-1))/2;
map<int,int> m;
while(n--){
int cur;
cin>>cur;
//cout<<" entered for"<<cur<<endl;
m[cur]+=1;
}
//auto it = map.begin();
int useless=0;
for(auto it=m.begin();it!=m.end();it++){
auto pai=(*it);
//cout<<"first is: "<<pai.first<<" second is "<<pai.second<<endl;
//auto pair=(*it);
int freq=pai.second;
if(freq>1){
useless=useless+(((freq)*(freq-1))/2);
}
}
cout<<tot-useless<<endl;
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}