import java.util.Arrays;
import java.util.Scanner;
//求反面
public class Main {
public static int MAX_LENGTH = 1001;
public static int[] v;
public static int[] iq;
static {
v = new int[MAX_LENGTH*MAX_LENGTH];
iq = new int[MAX_LENGTH];
}
public static long search(int[] value , int m ,int n ,int val ,int idx){
int l = idx , r = m ;
while(l<r){
int mid =( l + r )>>1;
if((long)value[mid] + val > n){
r = mid;
}else{
l = mid+1;
}
}
return m - l;
}
public static long match(int[] value, int m ,int n){
long result = 0;
Arrays.sort(value,0,m);
for(int i = 0; i < m-1 ;i++){
result += search(value, m , n , value[i] , i+1);
}
return result;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cas = in.nextInt();
while(cas-- >0){
long ans = 0;
int n = in.nextInt();
int k = in.nextInt();
int length = 0;
for(int i = 0 ; i < n ; i++){
int m = in.nextInt();
iq = new int[m];
for(int j = 0 ; j < m ;j++){
iq[j] = in.nextInt();
v[length++] = iq[j];
}
ans -= match(iq,m,k);
}
ans += match(v,length,k);
System.out.println(ans);
}
}
}
hdu Select 5101
最新推荐文章于 2022-04-11 19:48:47 发布