CF1392I.Kevin and Grid
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
As Kevin is in BigMan's house, suddenly a trap sends him onto a grid with n rows and m columns.
BigMan's trap is configured by two arrays: an array a1,a2,…,an and an array b1,b2,…,bm.
In the i-th row there is a heater which heats the row by ai degrees, and in the j-th column there is a heater which heats the column by bj degrees, so that the temperature of cell (i,j) is ai+bj.
Fortunately, Kevin has a suit with one parameter x and two modes:
- heat resistance. In this mode suit can stand all temperatures greater or equal to x, but freezes as soon as reaches a cell with temperature less than x.
- cold resistance. In this mode suit can stand all temperatures less than x, but will burn as soon as reaches a cell with temperature at least x.
Once Kevin lands on a cell the suit automatically turns to cold resistance mode if the cell has temperature less than x, or to heat resistance mode otherwise, and cannot change after that.
We say that two cells are adjacent if they share an edge.
Let a path be a sequence c1,c2,…,ck of cells such that ci and ci+1 are adjacent for 1≤i≤k−1.
We say that two cells are connected if there is a path between the two cells consisting only of cells that Kevin can step on.
A connected component is a maximal set of pairwise connected cells.
We say that a connected component is good if Kevin can escape the grid starting from it — when it contains at least one border cell of the grid, and that it's bad otherwise.
To evaluate the situation, Kevin gives a score of 1 to each good component and a score of 2 for each bad component.
The final score will be the difference between the total score of components with temperatures bigger than or equal to x and the score of components with temperatures smaller than x.
There are q possible values of x that Kevin can use, and for each of them Kevin wants to know the final score.
Help Kevin defeat BigMan!
当凯文身处大汉的房屋中时,突然触发了一个陷阱,将他传送到了一个 n 行 m 列的网格上。
大汉设计的陷阱由两个数组控制:数组 a1,a2,…,an 和数组 b1,b2,…,bm。
第 i 行有一个加热器,使该行升温 ai 度;第 j 列也有一个加热器,使该列升温 bj 度。因此,单元格 (i,j) 的温度为 ai+bj。
幸运的是,凯文身穿一套具有单一参数 x 且具备两种模式的防护服:
- 耐热模式:在此模式下,防护服可承受所有温度大于等于 x 的环境,但一旦进入温度严格小于 x 的单元格,便会立即冻结。
- 耐寒模式:在此模式下,防护服可承受所有温度严格小于 x 的环境,但一旦进入温度大于等于 x 的单元格,便会立即灼烧。
凯文落地于某个单元格后,防护服会自动切换至如下模式之一:若该单元格温度小于 x,则切换为耐寒模式;否则(即温度 ≥x)切换为耐热模式。此后防护服不可再切换模式。
我们称两个单元格相邻,当且仅当它们共享一条边。
定义一条路径为单元格序列 c1,c2,…,ck,满足对所有 1≤i≤k−1,ci 与 ci+1 相邻。
若存在一条仅由凯文可踏入的单元格构成的路径连接两个单元格,则称这两个单元格连通。
连通分量指一个极大的、两两连通的单元格集合。
若一个连通分量是好的,指凯文能从该分量出发成功逃出网格——即该分量中至少包含一个网格边界上的单元格;否则称为坏的。
为评估当前局势,凯文为每个好的连通分量赋予分数 1,为每个坏的连通分量赋予分数 2。
最终得分定义为:
所有温度 ≥x 的单元格所属连通分量的总分 减去
所有温度 <x 的单元格所属连通分量的总分。
凯文共有 q 种可能的 x 值可供选择,对于每种 x,他都需要知道对应的最终得分。
请帮助凯文击败大汉!
输入格式
The first line contains three integers n,m,q (1≤n,m,q≤105) – the number of rows, columns, and the number of possible values for x respectively.
The second line contains n integers a1,a2,…,an (1≤ai≤105).
The third line contains m integers b1,b2,…,bm (1≤bi≤105).
Each of the next q lines contains one integer x (1≤x≤2⋅105).
第一行包含三个整数 n、m、q(1≤n,m,q≤105),分别表示行数、列数以及可能的 x 值的个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤105)。
第三行包含 m 个整数 b1,b2,…,bm(1≤bi≤105)。
接下来的 q 行,每行包含一个整数 x(1≤x≤2⋅105)。
输出格式
Output q lines, in the i-th line output the answer for the i-th possible value of x from the input.
输出 q 行,第 i 行输出输入中第 i 个可能的 x 值所对应的答案。
输入输出样例
输入#1
5 5 1 1 3 2 3 1 1 3 2 3 1 5
输出#1
-1
输入#2
3 3 2 1 2 2 2 1 2 3 4
输出#2
0 1
说明/提示
In the first example, the score for components with temperature smaller than 5 is 1+2, and the score for components with temperature at least 5 is 2. Thus, the final score is 2−3=−1.
在第一个例子中,温度小于 5 的组件得分为 1+2,温度大于等于 5 的组件得分为 2。因此,最终得分为 2−3=−1。
输入解题思路,AI测评打分。不知道怎么写?