区间递增AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given integers $N,M,K$ and an integer sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$. It is guaranteed that each element of $A$ is between $0$ and $M-1$, inclusive.
You may perform the following operation on the integer sequence $A$ between $0$ and $K$ times, inclusive:
- Choose a pair of integers
$(l,r)$satisfying$1\le l\le r\le N$, and replace$A_k$with$(A_k+1) \bmod M$for each$k=l,l+1,\ldots,r$.
Find the lexicographically smallest $A$ after the operations.
You are given $T$ test cases; solve each of them.
What is lexicographic order on sequences? A sequence $S = (S_1,S_2,\ldots,S_{|S|})$ is lexicographically smaller than a sequence $T = (T_1,T_2,\ldots,T_{|T|})$ if one of the following conditions holds. Here, $|S|$ and $|T|$ denote the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following hold. $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$ $S_i$ is (numerically) smaller than $T_i$.
给定整数 $N,M,K$ 以及一个长度为 $N$ 的整数序列 $A=(A_1,A_2,\ldots,A_N)$。保证 $A$ 中的每个元素都在 $0$ 到 $M-1$(含)之间。
你可以对整数序列 $A$ 执行以下操作,操作次数在 $0$ 次到 $K$ 次(含)之间:
- 选择一对满足
$1\le l\le r\le N$的整数$(l,r)$,并将每个$k=l,l+1,\ldots,r$对应的$A_k$替换为$(A_k+1) \bmod M$。
求执行操作后,字典序最小的 $A$。
给定 $T$ 组测试数据,请分别求出每组测试数据的答案。
序列的字典序是什么?如果以下条件之一成立,则称长度分别为 $|S|$ 和 $|T|$ 的序列 $S = (S_1,S_2,\ldots,S_{|S|})$ 按字典序小于序列 $T = (T_1,T_2,\ldots,T_{|T|})$。这里,$|S|$ 和 $|T|$ 分别表示 $S$ 和 $T$ 的长度。
$|S| \lt |T|$ 且 $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$。
存在一个整数 $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$,使得以下两个条件均成立:$(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$,并且 $S_i$ 在数值上小于 $T_i$。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\le T\le 3\times 10^5$$1\le N\le 3\times 10^5$$2\le M\le 10^9$$1\le K\le 10^{15}$$0\le A_i < M$- The sum of
$N$over all test cases is at most$3\times 10^5$. - All input values are integers.
$1\le T\le 3\times 10^5$$1\le N\le 3\times 10^5$$2\le M\le 10^9$$1\le K\le 10^{15}$$0\le A_i < M$- 所有测试数据中
$N$的总和不超过$3\times 10^5$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入中给出,格式如下:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试数据的格式如下:AI (CI翻译)
N M K
A_1 A_2 \ldots A_N
N M K
A_1 A_2 \ldots A_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answers for the test cases in order, separated by newlines.
按顺序输出各组测试数据的答案,并以换行分隔。AI (CI翻译)
For each test case, output the elements of the lexicographically smallest $A$ after the operations, separated by spaces.
对于每组测试数据,将执行操作后字典序最小的 $A$ 的各个元素以空格分隔输出。AI (CI翻译)
样例
3
4 6 3
2 5 4 1
4 17 100
2 0 2 6
5 10 6
2 6 5 3 9
2 0 0 1
0 0 0 0
2 0 0 3 0
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。