fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long N,n;
  4.  
  5. int main() {
  6. cin.tie(0);
  7. cout.tie(0);
  8. ios_base::sync_with_stdio(false);
  9. cin>>N;
  10. while(N>0){
  11. long s[100000];
  12. long all=0,sm=0,now=0;
  13. cin>>n;
  14. for(long i=0;i<n;i++)
  15. cin>>s[i];
  16. sort(s,s+n);
  17. sm=0;//較小值的數量
  18. //cout<<N<<" "<<endl;
  19. for(long i=0;i<n;i++){
  20. if(s[i]==s[i+1]){
  21. now++;
  22. continue;
  23. }
  24. now++;
  25. all+=sm*now*(n-sm-now);
  26. //cout<<all<<endl;
  27. sm+=now;
  28. now=0;
  29. }
  30. cout<<all<<"\n";
  31. N--;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 5300KB
stdin
4
3
1 2 3
5
1 2 3 4 5
4 
1 2 3 3
4
3 3 3 3
stdout
1
10
2
0