CF1605E.Array Equalizer
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Jeevan has two arrays a and b of size n. He is fond of performing weird operations on arrays. This time, he comes up with two types of operations:
- Choose any i (1≤i≤n) and increment aj by 1 for every j which is a multiple of i and 1≤j≤n.
- Choose any i (1≤i≤n) and decrement aj by 1 for every j which is a multiple of i and 1≤j≤n.
He wants to convert array a into an array b using the minimum total number of operations. However, Jeevan seems to have forgotten the value of b1. So he makes some guesses. He will ask you q questions corresponding to his q guesses, the i-th of which is of the form:
- If b1=xi, what is the minimum number of operations required to convert a to b?
Help him by answering each question.
吉凡有两个长度为 n 的数组 a 和 b。他热衷于对数组执行各种奇怪的操作。这一次,他提出了两种类型的操作:
- 任选一个 i(1≤i≤n),对所有满足 j 是 i 的倍数且 1≤j≤n 的下标 j,将 aj 加 1;
- 任选一个 i(1≤i≤n),对所有满足 j 是 i 的倍数且 1≤j≤n 的下标 j,将 aj 减 1。
他希望用最少的总操作次数将数组 a 变为数组 b。然而,吉凡似乎忘记了 b1 的值,于是他做了一些猜测。他将向你提出 q 个问题,对应他的 q 次猜测;其中第 i 个问题的形式为:
- 若 b1=xi,则将 a 变为 b 所需的最少操作次数是多少?
请回答每一个问题。
输入格式
The first line contains a single integer n (1≤n≤2⋅105) — the size of arrays a and b.
The second line contains n integers a1,a2,...,an (1≤ai≤106).
The third line contains n integers b1,b2,...,bn (1≤bi≤106 for i=1; b1=−1, representing that the value of b1 is unknown).
The fourth line contains a single integer q (1≤q≤2⋅105) — the number of questions.
Each of the following q lines contains a single integer xi (1≤xi≤106) — representing the i-th question.
第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组 a 和 b 的大小。
第二行包含 n 个整数 a1,a2,...,an(1≤ai≤106)。
第三行包含 n 个整数 b1,b2,...,bn(当 i=1 时,1≤bi≤106;而 b1=−1,表示 b1 的值未知)。
第四行包含一个整数 q(1≤q≤2⋅105)—— 表示询问的次数。
接下来的 q 行中,每行包含一个整数 xi(1≤xi≤106)—— 表示第 i 次询问。
输出格式
Output q integers — the answers to each of his q questions.
输出 q 个整数——即他对 q 个问题的回答。
输入输出样例
输入#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=1: We need to convert [3,7]→[1,5]. We can perform the following operations:
[3,7] i = 1decrease [2,6] i = 1decrease [1,5]
Hence the answer is 2.
-
b1=4: We need to convert [3,7]→[4,5]. We can perform the following operations:
[3,7] i = 2decrease [3,6] i = 2decrease [3,5] i = 1increase [4,6] i = 2decrease [4,5]
Hence the answer is 4.
-
b1=3: We need to convert [3,7]→[3,5]. We can perform the following operations:
[3,7] i = 2decrease [3,6] i = 2decrease [3,5]
Hence the answer is 2.
考虑第一个测试用例。
-
b1=1:我们需要将 [3,7]→[1,5]。可执行如下操作:
[3,7] i = 1减少 [2,6] i = 1减少 [1,5]
因此答案为 2。
-
b1=4:我们需要将 [3,7]→[4,5]。可执行如下操作:
[3,7] i = 2减少 [3,6] i = 2减少 [3,5] i = 1增加 [4,6] i = 2减少 [4,5]
因此答案为 4。
-
b1=3:我们需要将 [3,7]→[3,5]。可执行如下操作:
[3,7] i = 2减少 [3,6] i = 2减少 [3,5]
因此答案为 2。
输入解题思路,AI测评打分。不知道怎么写?