CF1718C.Tonya and Burenka-179

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Tonya was given an array of aa of length nn written on a postcard for his birthday. For some reason, the postcard turned out to be a cyclic array, so the index of the element located strictly to the right of the nn-th is 11. Tonya wanted to study it better, so he bought a robot "Burenka-179".

A program for Burenka is a pair of numbers (s,k)(s, k), where 1≤s≤n1 \leq s \leq n, 1≤k≤n−11 \leq k \leq n-1. Note that kk cannot be equal to nn. Initially, Tonya puts the robot in the position of the array ss. After that, Burenka makes exactly nn steps through the array. If at the beginning of a step Burenka stands in the position ii, then the following happens:

  1. The number aia_{i} is added to the usefulness of the program.
  2. "Burenka" moves kk positions to the right (i:=i+ki := i + k is executed, if ii becomes greater than nn, then i:=i−ni := i - n).

Help Tonya find the maximum possible usefulness of a program for "Burenka" if the initial usefulness of any program is 00.

Also, Tony's friend Ilyusha asks him to change the array qq times. Each time he wants to assign ap:=xa_p := x for a given index pp and a value xx. You need to find the maximum possible usefulness of the program after each of these changes.

托尼娅生日时收到了一张明信片,上面写着一个长度为 nn 的数组 aa。不知为何,这张明信片上的数组是循环数组,即第 nn 个元素右侧紧邻的元素下标为 11。为了更深入地研究它,托尼娅购买了一台名为“布伦卡-179”的机器人。

“布伦卡”的一个程序是一个二元组 (s,k)(s, k),其中 1≤s≤n1 \leq s \leq n,1≤k≤n−11 \leq k \leq n-1。注意:kk 不能等于 nn。初始时,托尼娅将机器人置于数组的第 ss 个位置。随后,“布伦卡”在数组上恰好执行 nn 步。若某步开始时机器人位于位置 ii,则发生如下事件:

  1. 将数值 aia_{i} 加入该程序的效用值(usefulness);
  2. “布伦卡”向右移动 kk 个位置(执行 i:=i+ki := i + k;若 ii 超过 nn,则令 i:=i−ni := i - n)。

请帮助托尼娅求出“布伦卡”程序所能达到的最大可能效用值(初始效用值为 00)。

此外,托尼娅的朋友伊利沙请求他修改数组 qq 次。每次操作给定下标 pp 和值 xx,要求将 apa_p 修改为 xx。你需要在每次修改后,求出此时程序所能达到的最大可能效用值。

输入格式

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

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — elements of the array.

The following qq lines contain changes, each of them contains two integers pp and xx (1≤p≤n1 \leq p \leq n, 1≤x≤1091 \leq x \leq 10^9), meaning you should assign ap:=xa_p := x.

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

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

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

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示数组的元素。

接下来的 qq 行描述修改操作,每行包含两个整数 pp 和 xx(1≤p≤n1 \leq p \leq n,1≤x≤1091 \leq x \leq 10^9),表示将 apa_p 赋值为 xx。

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

输出格式

For each test case, output q+1q+1 numbers — the maximum usefulness of a program initially and after each of the changes.

对于每个测试用例,输出 q+1q+1 个数字——分别为程序初始时以及每次修改后的最大有用性。

输入输出样例

  • 输入#1

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

    输出#1

    3
    5
    14
    16
    24
    24
    24
    57
    54
    36
    36
    6
    18
    27
    28

说明/提示

In the first test case, initially and after each request, the answer is achieved at s=1s = 1, k=1k = 1 or s=2s = 2, k=1k = 1.

In the second test case, initially, the answer is achieved when s=1s = 1, k=2k = 2 or s=3s = 3, k=2k = 2. After the first request, the answer is achieved at s=2s = 2, k=2k = 2 or s=4s = 4, k=2k = 2.

在第一个测试用例中,初始状态及每次请求后,答案均在 s=1s = 1、k=1k = 1 或 s=2s = 2、k=1k = 1 时取得。

在第二个测试用例中,初始状态下,答案在 s=1s = 1、k=2k = 2 或 s=3s = 3、k=2k = 2 时取得;第一次请求后,答案在 s=2s = 2、k=2k = 2 或 s=4s = 4、k=2k = 2 时取得。

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

首页