CF1884E.Hard Design

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Consider an array of integers b0,b1,…,bn−1b_0, b_1, \ldots, b_{n-1}. Your goal is to make all its elements equal. To do so, you can perform the following operation several (possibly, zero) times:

  • Pick a pair of indices 0≤l≤r≤n−10 \le l \le r \le n-1, then for each l≤i≤rl \le i \le r increase bib_i by 11 (i. e. replace bib_i with bi+1b_i + 1).
  • After performing this operation you receive (r−l+1)2(r - l + 1)^2 coins.

The value f(b)f(b) is defined as a pair of integers (cnt,cost)(cnt, cost), where cntcnt is the smallest number of operations required to make all elements of the array equal, and costcost is the largest total number of coins you can receive among all possible ways to make all elements equal within cntcnt operations. In other words, first, you need to minimize the number of operations, second, you need to maximize the total number of coins you receive.

You are given an array of integers a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1}. Please, find the value of ff for all cyclic shifts of aa.

Formally, for each 0≤i≤n−10 \le i \le n-1 you need to do the following:

  • Let cj=a(j+i)(modn)c_j = a_{(j + i) \pmod{n}} for each 0≤j≤n−10 \le j \le n-1.
  • Find f(c)f(c). Since costcost can be very large, output it modulo (109+7)(10^9 + 7).

Please note that under a fixed cntcnt you need to maximize the total number of coins costcost, not its remainder modulo (109+7)(10^9 + 7).

考虑一个整数数组 b0,b1,…,bn−1b_0, b_1, \ldots, b_{n-1}。你的目标是使该数组所有元素相等。为此,你可以执行以下操作若干次(可能为零次):

  • 选择一对下标 0≤l≤r≤n−10 \le l \le r \le n-1,然后对每个满足 l≤i≤rl \le i \le r 的 ii,将 bib_i 增加 11(即用 bi+1b_i + 1 替换 bib_i);
  • 执行该操作后,你将获得 (r−l+1)2(r - l + 1)^2 枚金币。

函数 f(b)f(b) 定义为一个二元组 (cnt,cost)(cnt, cost),其中 cntcnt 是使数组所有元素相等所需的最少操作次数,而 costcost 是在恰好使用 cntcnt 次操作的所有可行方案中,所能获得的金币总数的最大值。换言之,首先需最小化操作次数,其次在满足该最小操作次数的前提下,最大化所获金币总数。

现给定一个整数数组 a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1}。请对数组 aa 的所有循环移位,分别求出其对应的 ff 值。

形式化地,对每个 0≤i≤n−10 \le i \le n-1,你需要执行以下步骤:

  • 对每个 0≤j≤n−10 \le j \le n-1,令 cj=a(j+i)(modn)c_j = a_{(j + i) \pmod{n}};
  • 求出 f(c)f(c)。由于 costcost 可能非常大,请将其对 (109+7)(10^9 + 7) 取模后输出。

请注意:在固定 cntcnt 的前提下,你需要最大化金币总数 costcost,而非其对 (109+7)(10^9 + 7) 取模后的结果。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤2⋅1041 \le t \le 2 \cdot 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1061 \le n \le 10^6).

The second line of each test case contains nn integers a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1} (1≤ai≤1091 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1061 \le n \le 10^6)。

每个测试用例的第二行包含 nn 个整数 a0,a1,…,an−1a_0, a_1, \ldots, a_{n-1}(1≤ai≤1091 \le a_i \le 10^9)。

保证所有测试用例的 nn 值之和不超过 10610^6。

输出格式

For each test case, for each 0≤i≤n−10 \le i \le n-1 output the value of ff for the ii-th cyclic shift of array aa: first, output cntcnt (the minimum number of operations), then output costcost (the maximum number of coins these operations can give) modulo 109+710^9 + 7.

对于每个测试用例,对每个 0≤i≤n−10 \le i \le n-1,输出数组 aa 的第 ii 个循环移位对应的函数 ff 的值:首先输出 cntcnt(最少操作次数),然后输出 costcost(这些操作所能获得的最大金币数)对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    5
    1
    1
    3
    1 3 2
    5
    3 2 4 5 1
    8
    6 5 6 4 2 6 2 2
    4
    10 10 10 10

    输出#1

    0 0
    3 3
    2 5
    2 5
    7 18
    7 16
    6 22
    5 28
    5 28
    9 27
    9 27
    9 27
    9 27
    11 23
    9 27
    9 27
    13 19
    0 0
    0 0
    0 0
    0 0

说明/提示

In the first test case, there is only one cycle shift, which is equal to [1][1], and all its elements are already equal.

In the second test case, you need to find the answer for three arrays:

  1. f([1,3,2])=(3,3)f([1, 3, 2]) = (3, 3).
  2. f([3,2,1])=(2,5)f([3, 2, 1]) = (2, 5).
  3. f([2,1,3])=(2,5)f([2, 1, 3]) = (2, 5).

Consider the case of [2,1,3][2, 1, 3]. To make all elements equal, we can pick l=1l = 1 and r=1r = 1 on the first operation, which results in [2,2,3][2, 2, 3]. On the second operation we can pick l=0l = 0 and r=1r = 1, which results in [3,3,3][3, 3, 3]. We have used 22 operations, and the total number of coins received is 12+22=51^2 + 2^2 = 5.

在第一个测试用例中,只有一个循环移位,即 [1][1],且其所有元素已经相等。

在第二个测试用例中,你需要对以下三个数组分别求解:

  1. f([1,3,2])=(3,3)f([1, 3, 2]) = (3, 3)。
  2. f([3,2,1])=(2,5)f([3, 2, 1]) = (2, 5)。
  3. f([2,1,3])=(2,5)f([2, 1, 3]) = (2, 5)。

考虑数组 [2,1,3][2, 1, 3] 的情况。为使所有元素相等,我们可在第一次操作中选取 l=1l = 1 和 r=1r = 1,得到 [2,2,3][2, 2, 3];在第二次操作中选取 l=0l = 0 和 r=1r = 1,得到 [3,3,3][3, 3, 3]。共使用了 22 次操作,获得的金币总数为 12+22=51^2 + 2^2 = 5。

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

首页