AT_arc220_c.Range Increment
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given integers N,M,K and an integer sequence A=(A1,A2,…,AN) 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≤l≤r≤N, and replace Ak with (Ak+1)modM for each k=l,l+1,…,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=(S1,S2,…,S∣S∣) is lexicographically smaller than a sequence T=(T1,T2,…,T∣T∣) if one of the following conditions holds. Here, ∣S∣ and ∣T∣ denote the lengths of S and T, respectively.
- ∣S∣<∣T∣ and (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣).
- There exists an integer 1≤i≤min{∣S∣,∣T∣} such that both of the following hold.
- (S1,S2,…,Si−1)=(T1,T2,…,Ti−1)
- Si is (numerically) smaller than Ti.
给你整数 N,M,K 和一个长度为 N 的整数序列 A=(A1,A2,…,AN)。保证 A 的每个元素均在 0 到 M−1(含端点)之间。
你可以在整数序列 A 上执行以下操作,执行次数为 0 到 K 次(含端点):
- 选择一对满足 1≤l≤r≤N 的整数 (l,r),并对每个 k=l,l+1,…,r,将 Ak 替换为 (Ak+1)modM。
求经过若干次操作后字典序最小的 A。
你将得到 T 组测试数据;请分别求解每组数据。
什么是序列的字典序?
序列 S=(S1,S2,…,S∣S∣) 字典序小于 序列 T=(T1,T2,…,T∣T∣),当且仅当满足下列条件之一。其中 ∣S∣ 和 ∣T∣ 分别表示 S 和 T 的长度。
- ∣S∣<∣T∣ 且 (S1,S2,…,S∣S∣)=(T1,T2,…,T∣S∣)。
- 存在整数 1≤i≤min{∣S∣,∣T∣},使得同时满足:
- (S1,S2,…,Si−1)=(T1,T2,…,Ti−1);
- Si(数值上)小于 Ti。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M K
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N M K
A1 A2 … AN
输出格式
Output the answers for the test cases in order, separated by newlines.
For each test case, output the elements of the lexicographically smallest A after the operations, separated by spaces.
按测试用例的顺序输出答案,各答案之间用换行符分隔。
对于每个测试用例,输出执行操作后字典序最小的 A 的各个元素,元素之间用空格分隔。
输入输出样例
输入#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).
- Operation 1: Choose (l,r)=(2,3). Now A=(2,0,5,1).
- Operation 2: Choose (l,r)=(3,3). Now A=(2,0,0,1).
Constraints
- 1≤T≤3×105
- 1≤N≤3×105
- 2≤M≤109
- 1≤K≤1015
- 0≤Ai<M
- The sum of N over all test cases is at most 3×105.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过执行以下两次操作,我们可以得到 A=(2,0,0,1)。
- 操作 1:选择 (l,r)=(2,3)。此时 A=(2,0,5,1)。
- 操作 2:选择 (l,r)=(3,3)。此时 A=(2,0,0,1)。
约束条件
- 1≤T≤3×105
- 1≤N≤3×105
- 2≤M≤109
- 1≤K≤1015
- 0≤Ai<M
- 所有测试用例的 N 之和不超过 3×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?