1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 using namespace std;
5 #define LL long long
6 LL f[1005],a[1005][105],b[1000005];
7 int main()
8 {
9 LL n,k,i,cnt,x1,x2,j,ans;
10 int T;
11 scanf("%d",&T);
12 while (T--)
13 {
14 scanf("%I64d%I64d",&n,&k);
15 cnt=0;
16 for (i=1;i<=n;i++)
17 {
18 scanf("%I64d",&f[i]);
19 for (j=1;j<=f[i];j++)
20 {
21 scanf("%I64d",&a[i][j]);
22 b[++cnt]=a[i][j];
23 }
24 sort(a[i]+1,a[i]+f[i]+1);
25 }
26 sort(b+1,b+cnt+1);
27 ans=0;
28 for (i=1;i<=n;i++)
29 for (j=1;j<=f[i];j++)
30 {
31 x1=lower_bound(a[i]+1,a[i]+f[i]+1,k-a[i][j]+1)-a[i];
32 x2=lower_bound(b+1,b+cnt+1,k-a[i][j]+1)-b;
33 ans+=(cnt-x2+1)-(f[i]-x1+1);
34 }
35 printf("%I64d\n",ans/2);
36 }
37 }
http://acm.hdu.edu.cn/showproblem.php?pid=5101