CF1605E.Array Equalizer

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Jeevan has two arrays aa and bb of size nn. He is fond of performing weird operations on arrays. This time, he comes up with two types of operations:

  • Choose any ii (1≤i≤n1 \le i \le n) and increment aja_j by 11 for every jj which is a multiple of ii and 1≤j≤n1 \le j \le n.
  • Choose any ii (1≤i≤n1 \le i \le n) and decrement aja_j by 11 for every jj which is a multiple of ii and 1≤j≤n1 \le j \le n.

He wants to convert array aa into an array bb using the minimum total number of operations. However, Jeevan seems to have forgotten the value of b1b_1. So he makes some guesses. He will ask you qq questions corresponding to his qq guesses, the ii-th of which is of the form:

  • If b1=xib_1 = x_i, what is the minimum number of operations required to convert aa to bb?

Help him by answering each question.

吉凡有两个长度为 nn 的数组 aa 和 bb。他热衷于对数组执行各种奇怪的操作。这一次,他提出了两种类型的操作:

  • 任选一个 ii(1≤i≤n1 \le i \le n),对所有满足 jj 是 ii 的倍数且 1≤j≤n1 \le j \le n 的下标 jj,将 aja_j 加 11;
  • 任选一个 ii(1≤i≤n1 \le i \le n),对所有满足 jj 是 ii 的倍数且 1≤j≤n1 \le j \le n 的下标 jj,将 aja_j 减 11。

他希望用最少的总操作次数将数组 aa 变为数组 bb。然而,吉凡似乎忘记了 b1b_1 的值,于是他做了一些猜测。他将向你提出 qq 个问题,对应他的 qq 次猜测;其中第 ii 个问题的形式为:

  • 若 b1=xib_1 = x_i,则将 aa 变为 bb 所需的最少操作次数是多少?

请回答每一个问题。

输入格式

The first line contains a single integer nn (1≤n≤2⋅105)(1 \le n \le 2 \cdot 10^{5}) — the size of arrays aa and bb.

The second line contains nn integers a1,a2,...,ana_1, a_2, ..., a_n (1≤ai≤106)(1 \le a_i \le 10^6).

The third line contains nn integers b1,b2,...,bnb_1, b_2, ..., b_n (1≤bi≤106(1 \le b_i \le 10^6 for i≠1i \neq 1; b1=−1b_1 = -1, representing that the value of b1b_1 is unknown)).

The fourth line contains a single integer qq (1≤q≤2⋅105)(1 \le q \le 2 \cdot 10^{5}) — the number of questions.

Each of the following qq lines contains a single integer xix_i (1≤xi≤106)(1 \le x_i \le 10^6) — representing the ii-th question.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^{5})—— 表示数组 aa 和 bb 的大小。

第二行包含 nn 个整数 a1,a2,...,ana_1, a_2, ..., a_n(1≤ai≤1061 \le a_i \le 10^6)。

第三行包含 nn 个整数 b1,b2,...,bnb_1, b_2, ..., b_n(当 i≠1i \neq 1 时,1≤bi≤1061 \le b_i \le 10^6;而 b1=−1b_1 = -1,表示 b1b_1 的值未知)。

第四行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^{5})—— 表示询问的次数。

接下来的 qq 行中,每行包含一个整数 xix_i(1≤xi≤1061 \le x_i \le 10^6)—— 表示第 ii 次询问。

输出格式

Output qq integers — the answers to each of his qq questions.

输出 qq 个整数——即他对 qq 个问题的回答。

输入输出样例

  • 输入#1

    2
    3 7
    -1 5
    3
    1
    4
    3

    输出#1

    2
    4
    2
  • 输入#2

    6
    2 5 4 1 3 6
    -1 4 6 2 3 5
    3
    1
    8
    4

    输出#2

    10
    29
    9

说明/提示

Consider the first test case.

  • b1=1b_1 = 1: We need to convert [3,7]→[1,5][3, 7] \rightarrow [1, 5]. We can perform the following operations:

    [3,7][3, 7] →decreasei = 1\xrightarrow[\text{decrease}]{\text{i = 1}} [2,6][2, 6] →decreasei = 1\xrightarrow[\text{decrease}]{\text{i = 1}} [1,5][1, 5]

    Hence the answer is 22.

  • b1=4b_1 = 4: We need to convert [3,7]→[4,5][3, 7] \rightarrow [4, 5]. We can perform the following operations:

    [3,7][3, 7] →decreasei = 2\xrightarrow[\text{decrease}]{\text{i = 2}} [3,6][3, 6] →decreasei = 2\xrightarrow[\text{decrease}]{\text{i = 2}} [3,5][3, 5] →increasei = 1\xrightarrow[\text{increase}]{\text{i = 1}} [4,6][4, 6] →decreasei = 2\xrightarrow[\text{decrease}]{\text{i = 2}} [4,5][4, 5]

    Hence the answer is 44.

  • b1=3b_1 = 3: We need to convert [3,7]→[3,5][3, 7] \rightarrow [3, 5]. We can perform the following operations:

    [3,7][3, 7] →decreasei = 2\xrightarrow[\text{decrease}]{\text{i = 2}} [3,6][3, 6] →decreasei = 2\xrightarrow[\text{decrease}]{\text{i = 2}} [3,5][3, 5]

    Hence the answer is 22.

考虑第一个测试用例。

  • b1=1b_1 = 1:我们需要将 [3,7]→[1,5][3, 7] \rightarrow [1, 5]。可执行如下操作:

    [3,7][3, 7] →减少i = 1\xrightarrow[\text{减少}]{\text{i = 1}} [2,6][2, 6] →减少i = 1\xrightarrow[\text{减少}]{\text{i = 1}} [1,5][1, 5]

    因此答案为 22。

  • b1=4b_1 = 4:我们需要将 [3,7]→[4,5][3, 7] \rightarrow [4, 5]。可执行如下操作:

    [3,7][3, 7] →减少i = 2\xrightarrow[\text{减少}]{\text{i = 2}} [3,6][3, 6] →减少i = 2\xrightarrow[\text{减少}]{\text{i = 2}} [3,5][3, 5] →增加i = 1\xrightarrow[\text{增加}]{\text{i = 1}} [4,6][4, 6] →减少i = 2\xrightarrow[\text{减少}]{\text{i = 2}} [4,5][4, 5]

    因此答案为 44。

  • b1=3b_1 = 3:我们需要将 [3,7]→[3,5][3, 7] \rightarrow [3, 5]。可执行如下操作:

    [3,7][3, 7] →减少i = 2\xrightarrow[\text{减少}]{\text{i = 2}} [3,6][3, 6] →减少i = 2\xrightarrow[\text{减少}]{\text{i = 2}} [3,5][3, 5]

    因此答案为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页