AT_arc220_c.Range Increment

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given integers N,M,KN,M,K and an integer sequence A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) of length NN. It is guaranteed that each element of AA is between 00 and M−1M-1, inclusive.

You may perform the following operation on the integer sequence AA between 00 and KK times, inclusive:

  • Choose a pair of integers (l,r)(l,r) satisfying 1≤l≤r≤N1\le l\le r\le N, and replace AkA_k with (Ak+1) mod M(A_k+1) \bmod M for each k=l,l+1,…,rk=l,l+1,\ldots,r.

Find the lexicographically smallest AA after the operations.

You are given TT test cases; solve each of them.

What is lexicographic order on sequences?

A sequence S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) is lexicographically smaller than a sequence T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}) if one of the following conditions holds. Here, ∣S∣|S| and ∣T∣|T| denote the lengths of SS and TT, respectively.

  1. ∣S∣<∣T∣|S| \lt |T| and (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|}).
  2. There exists an integer 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace such that both of the following hold.
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})
    • SiS_i is (numerically) smaller than TiT_i.

给你整数 N,M,KN,M,K 和一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N)。保证 AA 的每个元素均在 00 到 M−1M-1(含端点)之间。

你可以在整数序列 AA 上执行以下操作,执行次数为 00 到 KK 次(含端点):

  • 选择一对满足 1≤l≤r≤N1\le l\le r\le N 的整数 (l,r)(l,r),并对每个 k=l,l+1,…,rk=l,l+1,\ldots,r,将 AkA_k 替换为 (Ak+1) mod M(A_k+1) \bmod M。

求经过若干次操作后字典序最小的 AA。

你将得到 TT 组测试数据;请分别求解每组数据。

什么是序列的字典序?

序列 S=(S1,S2,…,S∣S∣)S = (S_1,S_2,\ldots,S_{|S|}) 字典序小于 序列 T=(T1,T2,…,T∣T∣)T = (T_1,T_2,\ldots,T_{|T|}),当且仅当满足下列条件之一。其中 ∣S∣|S| 和 ∣T∣|T| 分别表示 SS 和 TT 的长度。

  1. ∣S∣<∣T∣|S| \lt |T| 且 (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})。
  2. 存在整数 1≤i≤min⁡{∣S∣,∣T∣}1 \leq i \leq \min\lbrace |S|, |T| \rbrace,使得同时满足:
    • (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1});
    • SiS_i(数值上)小于 TiT_i。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

NN MM KK
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

NN MM KK
A1A_1 A2A_2 …\ldots ANA_N

输出格式

Output the answers for the test cases in order, separated by newlines.

For each test case, output the elements of the lexicographically smallest AA after the operations, separated by spaces.

按测试用例的顺序输出答案,各答案之间用换行符分隔。

对于每个测试用例,输出执行操作后字典序最小的 AA 的各个元素,元素之间用空格分隔。

输入输出样例

  • 输入#1

    3
    4 6 3
    2 5 4 1
    4 17 100
    2 0 2 6
    5 10 6
    2 6 5 3 9

    输出#1

    2 0 0 1
    0 0 0 0
    2 0 0 3 0

说明/提示

Sample 1 Explanation:
Consider the first test case.

By performing two operations as follows, we can obtain A=(2,0,0,1)A=(2,0,0,1).

  • Operation 11: Choose (l,r)=(2,3)(l,r)=(2,3). Now A=(2,0,5,1)A=(2,0,5,1).
  • Operation 22: Choose (l,r)=(3,3)(l,r)=(3,3). Now A=(2,0,0,1)A=(2,0,0,1).

Constraints

  • 1≤T≤3×1051\le T\le 3\times 10^5
  • 1≤N≤3×1051\le N\le 3\times 10^5
  • 2≤M≤1092\le M\le 10^9
  • 1≤K≤10151\le K\le 10^{15}
  • 0≤Ai<M0\le A_i < M
  • The sum of NN over all test cases is at most 3×1053\times 10^5.
  • All input values are integers.

样例 1 解释:
考虑第一个测试用例。

通过执行以下两次操作,我们可以得到 A=(2,0,0,1)A=(2,0,0,1)。

  • 操作 11:选择 (l,r)=(2,3)(l,r)=(2,3)。此时 A=(2,0,5,1)A=(2,0,5,1)。
  • 操作 22:选择 (l,r)=(3,3)(l,r)=(3,3)。此时 A=(2,0,0,1)A=(2,0,0,1)。

约束条件

  • 1≤T≤3×1051\le T\le 3\times 10^5
  • 1≤N≤3×1051\le N\le 3\times 10^5
  • 2≤M≤1092\le M\le 10^9
  • 1≤K≤10151\le K\le 10^{15}
  • 0≤Ai<M0\le A_i < M
  • 所有测试用例的 NN 之和不超过 3×1053\times 10^5。
  • 所有输入值均为整数。

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

首页