CF2193C.Replace and Sum

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Today, KQ has an exam at the Grail Academy. A strict teacher gave a task that KQ could not solve. He was given two arrays aa and bb of length nn. KQ is allowed to perform the following operations on the arrays:

  • Choose an index ii (1≤i<n1\le i\lt n) and replace aia_i with ai+1a_{i+1}.
  • Choose an index ii (1≤i≤n1\le i\le n) and replace aia_i with bib_i.

Now he has qq queries. Each query is described by two numbers ll and rr. His task is to find the maximum value of the sum (al+al+1+al+2+⋯+ar)(a_l + a_{l+1} + a_{l+2} + \dots + a_r) for each query, if he can perform any number of operations on any elements of the array. Since he is not skilled enough for this, he asks for your help.

今天,KQ 在圣杯学院有一场考试。一位严格的老师布置了一道 KQ 无法解决的题目。他被给定了两个长度均为 nn 的数组 aa 和 bb。KQ 可以对数组执行以下操作:

  • 选择一个下标 ii(满足 1≤i<n1 \le i < n),并将 aia_i 替换为 ai+1a_{i+1};
  • 选择一个下标 ii(满足 1≤i≤n1 \le i \le n),并将 aia_i 替换为 bib_i。

现在他有 qq 个查询。每个查询由两个数 ll 和 rr 描述。他的任务是:对每个查询,在可以对数组任意元素执行任意次数操作的前提下,求子段和 (al+al+1+al+2+⋯+ar)(a_l + a_{l+1} + a_{l+2} + \dots + a_r) 的最大可能值。由于他尚不具备解决此题的能力,因此向你求助。

输入格式

Each test consists of several test cases. The first line contains one integer tt (1≤t≤1041\le t\le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn, qq (1≤n,q≤2⋅105)(1\le n, q\le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,...,ana_1, a_2,...,a_n (1≤ai≤104)(1\le a_i\le 10^4).

The third line of each test case contains nn integers b1,b2,...,bnb_1, b_2,...,b_n (1≤bi≤104)(1\le b_i\le 10^4).

The following qq lines contain two integers ll and rr (1≤l≤r≤n)(1\le l\le r\le n).

It is guaranteed that the sum of the values of nn and the sum of the values of qq across all test cases do not exceed 2⋅1052 \cdot 10^5.

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤1041\le t\le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051\le n, q\le 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2,\dots,a_n(1≤ai≤1041\le a_i\le 10^4)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2,\dots,b_n(1≤bi≤1041\le b_i\le 10^4)。

接下来的 qq 行,每行包含两个整数 ll 和 rr(1≤l≤r≤n1\le l\le r\le n)。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output qq numbers separated by spaces — the maximum values of the sums (al+al+1+al+2+⋯+ar)(a_l + a_{l+1} + a_{l+2} + \dots + a_r).

对于每个测试用例,输出 qq 个用空格分隔的数字——即和 (al+al+1+al+2+⋯+ar)(a_l + a_{l+1} + a_{l+2} + \dots + a_r) 的最大值。

输入输出样例

  • 输入#1

    4
    3 1
    3 2 1
    1 2 3
    1 3
    1 1
    1
    2
    1 1
    3 2
    6 7 5
    9 6 8
    1 2
    2 3
    4 3
    4 3 2 1
    5 1 3 1
    1 2
    2 4
    3 4

    输出#1

    9
    2
    17 16
    8 7 4

说明/提示

Consider the first test case. Replace a3a_3 with b3b_3, a=[3,2,3]a = [3, 2, 3]. Replace a2a_2 with a3a_3, a=[3,3,3]a = [3, 3, 3]. The sum a1+a2+a3=9a_1 + a_2 + a_3 = 9.

考虑第一个测试用例。将 a3a_3 替换为 b3b_3,得到 a=[3,2,3]a = [3, 2, 3]。再将 a2a_2 替换为 a3a_3,得到 a=[3,3,3]a = [3, 3, 3]。此时和 a1+a2+a3=9a_1 + a_2 + a_3 = 9。

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

首页