-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMR14C.cpp
More file actions
38 lines (38 loc) · 750 Bytes
/
AMR14C.cpp
File metadata and controls
38 lines (38 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,x;
scanf("%d %d %d",&n,&m,&x);
long long arr[n],cum[m];
memset(cum,0,sizeof(cum));
for (int i=0; i<n; i++)
{
scanf("%lld",&arr[i]);
arr[i]%=m;
cum[arr[i]]++;
}
for (int i=1; i<m; i++)
cum[i]+=cum[i-1];
sort(arr,arr+n);
long long ans=0;
for (int i=m-1; i>x; i--)
{
int up_bound=m+x-i,low_bound=m-i;
ans+=(cum[up_bound]-cum[low_bound-1])*(cum[i]-cum[i-1]);
}
for (int i=x; i>0; i--)
{
int up_bound=m-i,low_bound=x-i;
ans+=(cum[m-1]-cum[up_bound-1])*(cum[i]-cum[i-1]);
ans+=(cum[low_bound])*(cum[i]-cum[i-1]);
}
ans+=(cum[x])*cum[0];
printf("%lld\n",ans);
}
return 0;
}//9939040626