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) and (106,106) .
The city has n vertical and m horizontal streets that goes across the whole city, i. e. the i -th vertical streets goes from (xi,0) to (xi,106) and the j -th horizontal street goes from (0,yj) to (106,yj) .
All streets are bidirectional. Borders of the city are streets as well.
There are k persons staying on the streets: the p -th person at point (xp,yp) (so either xp equal to some xi or yp equal to some yj , 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) and (y,x) are the same pair).
Let's recall that Manhattan distance between points (x1,y1) and (x2,y2) is ∣x1−x2∣+∣y1−y2∣ .
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
The first line of each test case contains three integers n , m and k ( 2≤n,m≤2⋅105 ; 2≤k≤3⋅105 ) — the number of vertical and horizontal streets and the number of persons.
The second line of each test case contains n integers x1,x2,…,xn ( 0=x1<x2<⋯<xn−1<xn=106 ) — the x -coordinates of vertical streets.
The third line contains m integers y1,y2,…,ym ( 0=y1<y2<⋯<ym−1<ym=106 ) — the y -coordinates of horizontal streets.
Next k lines contains description of people. The p -th line contains two integers xp and yp ( 0≤xp,yp≤106 ; xp∈{x1,…,xn} or yp∈{y1,…,ym} ) — the coordinates of the p -th person. All points are distinct.
It guaranteed that sum of n doesn't exceed 2⋅105 , sum of m doesn't exceed 2⋅105 and sum of k doesn't exceed 3⋅105 .
输出格式
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 3 and 4 form an inconvenient pair, since the shortest path between them (shown red and equal to 7 ) is greater than its Manhattan distance (equal to 5 ).
Points 3 and 5 also form an inconvenient pair: the shortest path equal to 1000001 (shown green) is greater than the Manhattan distance equal to 999999 .
But points 5 and 9 don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.