CF1392I.Kevin and Grid

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

As Kevin is in BigMan's house, suddenly a trap sends him onto a grid with nn rows and mm columns.

BigMan's trap is configured by two arrays: an array a1,a2,,ana_1,a_2,\ldots,a_n and an array b1,b2,,bmb_1,b_2,\ldots,b_m .

In the ii -th row there is a heater which heats the row by aia_i degrees, and in the jj -th column there is a heater which heats the column by bjb_j degrees, so that the temperature of cell (i,j)(i,j) is ai+bja_i+b_j .

Fortunately, Kevin has a suit with one parameter xx and two modes:

  • heat resistance. In this mode suit can stand all temperatures greater or equal to xx , but freezes as soon as reaches a cell with temperature less than xx .
  • cold resistance. In this mode suit can stand all temperatures less than xx , but will burn as soon as reaches a cell with temperature at least xx .

Once Kevin lands on a cell the suit automatically turns to cold resistance mode if the cell has temperature less than xx , 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,,ckc_1,c_2,\ldots,c_k of cells such that cic_i and ci+1c_{i+1} are adjacent for 1ik11 \leq i \leq 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 11 to each good component and a score of 22 for each bad component.

The final score will be the difference between the total score of components with temperatures bigger than or equal to xx and the score of components with temperatures smaller than xx .

There are qq possible values of xx that Kevin can use, and for each of them Kevin wants to know the final score.

Help Kevin defeat BigMan!

输入格式

The first line contains three integers nn , mm , qq ( 1n,m,q1051 \leq n,m,q \leq 10^5 ) – the number of rows, columns, and the number of possible values for xx respectively.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1051 \leq a_i \leq 10^5 ).

The third line contains mm integers b1,b2,,bmb_1, b_2, \dots, b_m ( 1bi1051 \leq b_i \leq 10^5 ).

Each of the next qq lines contains one integer xx ( 1x21051 \leq x \leq 2 \cdot 10^5 ).

输出格式

Output qq lines, in the ii -th line output the answer for the ii -th possible value of xx from the input.

输入输出样例

  • 输入#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 55 is 1+21+2 , and the score for components with temperature at least 55 is 22 . Thus, the final score is 23=12-3=-1 .

首页