fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. #define rd freopen("input.txt", "r", stdin)
  4. #define rw freopen("output.txt", "w", stdout)
  5. #define gg ios_base::sync_with_stdio(0)
  6.  
  7. using namespace std;
  8.  
  9. long long t, n, m, x, v, ar[100100], as[100100], t1, t2, res;
  10.  
  11. int main() {
  12. gg;
  13. //rd;
  14.  
  15. cin >> t;
  16. while (t--) {
  17. res = 0;
  18. cin >> n >> m >> x;
  19.  
  20. memset(ar, 0, sizeof(ar));
  21. memset(as, 0, sizeof(as));
  22.  
  23. for (int i = 0; i < n; i++) {
  24. cin >> v;
  25. v = v%m;
  26. ar[v]++;
  27. }
  28. as[0] = 0;
  29. for (int i = 1; i < m; i++) {
  30. as[i] = as[i - 1] + ar[i];
  31. }
  32. as[m] = as[m - 1] + ar[0];
  33.  
  34. for (int i = 0; i < m; i++) {
  35. if (i<=x) {
  36. res += as[x - i]*ar[i];
  37. res += (as[m] - as[m - i - 1])*ar[i];
  38. }
  39. else {
  40. res += (as[m + x - i] - as[m - i - 1])*ar[i];
  41. }
  42. }
  43. cout << res << endl;
  44. }
  45. }
Success #stdin #stdout 0s 5028KB
stdin
2
3 5 3
1 2 3
4 7 4
31 12 11 17
stdout
6
12