CF2181G.Greta's Game

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Greta and Alice are the two permanent hosts of the hit comedy show "QuestExpert". For this season they invited nn programmers to complete quests, set by Alice. After that they all meet in a studio to review how well they did and complete the final studio quest.

Today, the studio quest that Alice came up with is as follows: first, all nn participants stand in a circle in order from 11 to nn counter-clockwise. Then Alice holds some number of rounds. In each round, every participant writes down an integer on a piece of paper. After that, Alice checks the numbers and for each ii from 11 to nn, if the ii-th participant's number is strictly larger than the number of the next participant in counter-clockwise order (participant number (i mod n)+1(i \bmod n) + 1), then the ii-th and the (i mod n)+1(i \bmod n) + 1-st participants both receive one point. After all rounds are complete, Alice calculates the total number of points for each participant and reports them to Greta. It turned out that the ii-th participant scored aia_i points.

Greta thinks that math games are boring, and this one took too long. To prove her wrong, Alice decides to cheat a little and instead of telling Greta the real number of rounds, she will tell her the minimum possible number of rounds that could still result in the ii-th participant scoring aia_i points for each ii.

Help Alice determine this number.

格蕾塔和爱丽丝是热门喜剧节目《QuestExpert》的两位固定主持人。本季,她们邀请了 nn 名程序员来完成由爱丽丝设计的各项任务。之后,所有人齐聚演播室,回顾各自表现,并共同完成最终的演播室任务。

今天,爱丽丝设计的演播室任务如下:首先,所有 nn 名参与者按编号 11 到 nn 逆时针方向围成一个圆圈。接着,爱丽丝主持若干轮游戏。在每一轮中,每位参与者都在纸上写下一个整数。随后,爱丽丝检查这些数字;对每个 ii(从 11 到 nn),若第 ii 位参与者的数字严格大于其在逆时针方向上的下一位参与者(即编号为 (i mod n)+1(i \bmod n) + 1 的参与者)所写的数字,则第 ii 位与第 (i mod n)+1(i \bmod n) + 1 位参与者各得一分。待所有轮次结束后,爱丽丝统计每位参与者的总得分,并将结果告知格蕾塔。结果发现,第 ii 位参与者共获得 aia_i 分。

格蕾塔认为数学游戏枯燥乏味,且本次任务耗时过长。为了证明她错了,爱丽丝决定稍作“作弊”:她不告诉格蕾塔实际进行的轮数,而是告诉她——能够使得每位参与者 ii 恰好获得 aia_i 分的最少可能轮数。

请帮助爱丽丝确定这一最小轮数。

输入格式

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

The first line of each test case contains a single integer nn, denoting the number of participants (2≤n≤5⋅1052 \le n \le 5 \cdot 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, denoting the final scores of the participants (0≤ai≤1090 \le a_i \le 10^9). It is guaranteed that those scores were achieved in the described game with at least one round.

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn,表示参与者的数量(2≤n≤5⋅1052 \le n \le 5 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n,表示参与者的最终得分(0≤ai≤1090 \le a_i \le 10^9)。保证这些得分是在所述游戏中经过至少一轮后得到的。

保证所有测试用例的 nn 值之和不超过 5⋅1055 \cdot 10^5。

输出格式

For each test case, output on a separate line the minimum number of rounds that could lead to the given scores.

对于每个测试用例,在单独一行输出能够得到给定分数的最少轮数。

输入输出样例

  • 输入#1

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

    输出#1

    3
    2
    2
    4
    10

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

首页