CF1569D.Inconvenient Pairs

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a city that can be represented as a square grid with corner points in (0,0)(0, 0) and (106,106)(10^6, 10^6) .

The city has nn vertical and mm horizontal streets that goes across the whole city, i. e. the ii -th vertical streets goes from (xi,0)(x_i, 0) to (xi,106)(x_i, 10^6) and the jj -th horizontal street goes from (0,yj)(0, y_j) to (106,yj)(10^6, y_j) .

All streets are bidirectional. Borders of the city are streets as well.

There are kk persons staying on the streets: the pp -th person at point (xp,yp)(x_p, y_p) (so either xpx_p equal to some xix_i or ypy_p equal to some yjy_j , or both).

Let's say that a pair of persons form an inconvenient pair if the shortest path from one person to another going only by streets is strictly greater than the Manhattan distance between them.

Calculate the number of inconvenient pairs of persons (pairs (x,y)(x, y) and (y,x)(y, x) are the same pair).

Let's recall that Manhattan distance between points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is x1x2+y1y2|x_1 - x_2| + |y_1 - y_2| .

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The first line of each test case contains three integers nn , mm and kk ( 2n,m21052 \le n, m \le 2 \cdot 10^5 ; 2k31052 \le k \le 3 \cdot 10^5 ) — the number of vertical and horizontal streets and the number of persons.

The second line of each test case contains nn integers x1,x2,,xnx_1, x_2, \dots, x_n ( 0=x1<x2<<xn1<xn=1060 = x_1 < x_2 < \dots < x_{n - 1} < x_n = 10^6 ) — the xx -coordinates of vertical streets.

The third line contains mm integers y1,y2,,ymy_1, y_2, \dots, y_m ( 0=y1<y2<<ym1<ym=1060 = y_1 < y_2 < \dots < y_{m - 1} < y_m = 10^6 ) — the yy -coordinates of horizontal streets.

Next kk lines contains description of people. The pp -th line contains two integers xpx_p and ypy_p ( 0xp,yp1060 \le x_p, y_p \le 10^6 ; xp{x1,,xn}x_p \in \{x_1, \dots, x_n\} or yp{y1,,ym}y_p \in \{y_1, \dots, y_m\} ) — the coordinates of the pp -th person. All points are distinct.

It guaranteed that sum of nn doesn't exceed 21052 \cdot 10^5 , sum of mm doesn't exceed 21052 \cdot 10^5 and sum of kk doesn't exceed 31053 \cdot 10^5 .

输出格式

For each test case, print the number of inconvenient pairs.

输入输出样例

  • 输入#1

    2
    2 2 4
    0 1000000
    0 1000000
    1 0
    1000000 1
    999999 1000000
    0 999999
    5 4 9
    0 1 2 6 1000000
    0 4 8 1000000
    4 4
    2 5
    2 2
    6 3
    1000000 1
    3 8
    5 8
    8 8
    6 8

    输出#1

    2
    5

说明/提示

The second test case is pictured below:

For example, points 33 and 44 form an inconvenient pair, since the shortest path between them (shown red and equal to 77 ) is greater than its Manhattan distance (equal to 55 ).

Points 33 and 55 also form an inconvenient pair: the shortest path equal to 10000011000001 (shown green) is greater than the Manhattan distance equal to 999999999999 .

But points 55 and 99 don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.

首页