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 a and b of length n. KQ is allowed to perform the following operations on the arrays:
- Choose an index i (1≤i<n) and replace ai with ai+1.
- Choose an index i (1≤i≤n) and replace ai with bi.
Now he has q queries. Each query is described by two numbers l and r. His task is to find the maximum value of the sum (al+al+1+al+2+⋯+ar) 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 无法解决的题目。他被给定了两个长度均为 n 的数组 a 和 b。KQ 可以对数组执行以下操作:
- 选择一个下标 i(满足 1≤i<n),并将 ai 替换为 ai+1;
- 选择一个下标 i(满足 1≤i≤n),并将 ai 替换为 bi。
现在他有 q 个查询。每个查询由两个数 l 和 r 描述。他的任务是:对每个查询,在可以对数组任意元素执行任意次数操作的前提下,求子段和 (al+al+1+al+2+⋯+ar) 的最大可能值。由于他尚不具备解决此题的能力,因此向你求助。
输入格式
Each test consists of several test cases. The first line contains one integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n, q (1≤n,q≤2⋅105).
The second line of each test case contains n integers a1,a2,...,an (1≤ai≤104).
The third line of each test case contains n integers b1,b2,...,bn (1≤bi≤104).
The following q lines contain two integers l and r (1≤l≤r≤n).
It is guaranteed that the sum of the values of n and the sum of the values of q across all test cases do not exceed 2⋅105.
每个测试包含若干测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤2⋅105)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤104)。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤104)。
接下来的 q 行,每行包含两个整数 l 和 r(1≤l≤r≤n)。
保证所有测试用例中 n 的总和与 q 的总和均不超过 2⋅105。
输出格式
For each test case, output q numbers separated by spaces — the maximum values of the sums (al+al+1+al+2+⋯+ar).
对于每个测试用例,输出 q 个用空格分隔的数字——即和 (al+al+1+al+2+⋯+ar) 的最大值。
输入输出样例
输入#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 a3 with b3, a=[3,2,3]. Replace a2 with a3, a=[3,3,3]. The sum a1+a2+a3=9.
考虑第一个测试用例。将 a3 替换为 b3,得到 a=[3,2,3]。再将 a2 替换为 a3,得到 a=[3,3,3]。此时和 a1+a2+a3=9。
输入解题思路,AI测评打分。不知道怎么写?