2021-09-18

import java.io.*;
import java.util.Arrays;
import static java.lang.Math.abs;

public class Solution {

    public static void main(String[] args) throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        int T = nextInt();
        for (int tc = 1; tc <= T; tc++) {
            readCase();
            work();
            System.out.println("#" + tc + " " + ans1 + " " + ans2);
        }
    }

    static void work() {
        Arrays.sort(d, 0, N);
        ans1 = 0;
        ans2 = 0;
        for (int i = 0; i < M; i++) {
            if (abs(p[1][i]) > D) continue;
            if (abs(p[1][i]) == D) {
                int pos = Arrays.binarySearch(d, 0, N, p[0][i]);
                if (pos >= 0) {
                    ans1++;
                    ans2++;
                }
            } else {
                int len = D - abs(p[1][i]);
                int pos1 = Arrays.binarySearch(d, 0, N, p[0][i] + len);
                int pos2 = Arrays.binarySearch(d, 0, N, p[0][i] - len);
                if (pos1 == pos2) continue;//两点间无商铺
                if (pos1 < 0 && pos2 >= 0) {
                    pos1 = abs(pos1 + 1);
                    if (pos1 < pos2) pos1--;
                } else if (pos1 >= 0 && pos2 < 0) {
                    pos2 = abs(pos2 + 1);
                    if (pos2 < pos1) pos2--;
                } else {
                    pos1 = abs(pos1 + 1);
                    pos2 = abs(pos2 + 1);
                }
                ans1++;
                ans2 += abs(pos1 - pos2);
            }
        }
    }

    static void readCase() throws IOException {
        N = nextInt();
        M = nextInt();
        D = nextInt();
        for (int i = 0; i < N; i++) d[i] = nextInt();
        for (int i = 0; i < M; i++) {
            p[0][i] = nextInt();//x
            p[1][i] = nextInt();//y
        }
    }

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static StreamTokenizer in;
    static int N, M, D, ans1, ans2;
    static final int[] d = new int[100003];
    static final int[][] p = new int[2][100003];
}

3
4 3 3
-4 4 1 0
0 2
-3 -1
3 -3
1 1 1
1
2 0
1 1 1
1
2 1

#1 2 3
#2 1 1
#3 0 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值