CF1569D.Inconvenient Pairs
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
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∣.
存在一座城市,其形状可表示为一个正方形网格,左下角和右上角的坐标分别为 (0,0) 和 (106,106)。
该城市共有 n 条纵向街道和 m 条横向街道,贯穿整座城市:第 i 条纵向街道从 (xi,0) 延伸至 (xi,106);第 j 条横向街道从 (0,yj) 延伸至 (106,yj)。
所有街道均为双向通行。城市的边界本身也视为街道。
有 k 个人位于街道上:第 p 个人位于点 (xp,yp)(即满足 xp=xi(对某个 i)或 yp=yj(对某个 j),或两者同时成立)。
我们称一对人构成不便对(inconvenient pair),当且仅当他们之间仅沿街道行走的最短路径长度严格大于他们之间的曼哈顿距离。
请计算不便对的人数(注意:(x,y) 与 (y,x) 视为同一对)。
回顾:两点 (x1,y1) 与 (x2,y2) 之间的曼哈顿距离定义为 ∣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.
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。
每个测试用例的第一行包含三个整数 n、m 和 k(2≤n,m≤2⋅105;2≤k≤3⋅105)—— 分别表示竖直街道和水平街道的数量,以及人员数量。
每个测试用例的第二行包含 n 个整数 x1,x2,…,xn(0=x1<x2<⋯<xn−1<xn=106)—— 表示竖直街道的 x 坐标。
第三行包含 m 个整数 y1,y2,…,ym(0=y1<y2<⋯<ym−1<ym=106)—— 表示水平街道的 y 坐标。
接下来的 k 行描述人员信息。第 p 行包含两个整数 xp 和 yp(0≤xp,yp≤106;且满足 xp∈{x1,…,xn} 或 yp∈{y1,…,ym})—— 表示第 p 个人的坐标。所有点互不相同。
保证所有测试用例中 n 的总和不超过 2⋅105,m 的总和不超过 2⋅105,k 的总和不超过 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.
第二个测试用例如下图所示:

例如,点 3 和点 4 构成一对“不便点对”,因为它们之间的最短路径(图中以红色标出,长度为 7)大于其曼哈顿距离(等于 5)。
点 3 和点 5 同样构成一对“不便点对”:其最短路径长度为 1000001(图中以绿色标出),大于其曼哈顿距离 999999。
但点 5 和点 9 并不构成“不便点对”,因为它们之间的最短路径(图中以紫色标出)等于其曼哈顿距离。
输入解题思路,AI测评打分。不知道怎么写?