fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--){
  8. int n,k;
  9. cin>>n>>k;
  10. int *array = new int[n];
  11. for(int i = 0;i<n;i++){
  12. cin>>array[i];
  13. }
  14. int p = 0;
  15. for(int i=0;i<n-1;i++){
  16. for(int j=i+1;j<n;j++){
  17. if(array[i]>array[j]){
  18. p++;
  19. }
  20. }
  21. }
  22. int ans = p*k,q=0;
  23. for(int i=0;i<n;i++){
  24. for(int j=0;j<n;j++){
  25. if(array[i]>array[j]){
  26. q++;
  27. }
  28. }
  29. }
  30. int ans1 = ans + (k*(k-1)*q)/2;
  31. cout<<ans1<<endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
Standard output is empty