AT_abc478_c.Sort Subarray
普及-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a length-N integer sequence A=(A1,A2,…,AN).
You will perform the following operation on A exactly once.
- Choose an integer i between 1 and N−K+1, inclusive. Sort Ai,Ai+1,…,Ai+K−1 in ascending order. More formally, let B1,B2,…,BK be Ai,Ai+1,…,Ai+K−1 arranged in increasing order, and simultaneously replace Ai+j−1 with Bj for 1≤j≤K.
Determine whether it is possible that, after this operation, A is in ascending order, that is, Ai≤Ai+1 holds for all 1≤i<N.
给你一个长度为 N 的整数序列 A=(A1,A2,…,AN)。
你将对 A 恰好执行一次如下操作:
- 选择一个整数 i,满足 1≤i≤N−K+1。将子数组 Ai,Ai+1,…,Ai+K−1 按升序排序。更准确地说,设 B1,B2,…,BK 是 Ai,Ai+1,…,Ai+K−1 按升序排列后的结果,并同时将每个 Ai+j−1 替换为 Bj(其中 1≤j≤K)。
判断:在执行该操作后,是否可能使 A 成为升序序列,即对所有 1≤i<N 均满足 Ai≤Ai+1。
输入格式
The input is given from Standard Input in the following format:
N K
A1 A2 … AN
输入从标准输入中按以下格式给出:
N K
A1 A2 … AN
输出格式
If A can be sorted in ascending order by performing the operation once, output Yes; otherwise, output No.
如果通过对 A 执行一次该操作即可将其按升序排序,则输出 Yes;否则,输出 No。
输入输出样例
输入#1
9 6 1 4 1 4 2 1 3 5 6
输出#1
Yes
输入#2
3 1 3 2 1
输出#2
No
输入#3
30 25 1 2 2 22 14 10 14 10 18 5 15 8 17 22 10 17 11 25 13 16 9 19 26 7 11 12 23 3 30 30
输出#3
Yes
说明/提示
Sample 1 Explanation:
For example, if you choose 2 as i, then (A2,A3,A4,A5,A6,A7)=(4,1,4,2,1,3) is replaced with (1,1,2,3,4,4). After the operation, A is (1,1,1,2,3,4,4,5,6), which satisfies the condition.
Thus, output Yes.
Sample 2 Explanation:
K=1, so A does not change regardless of which i the operation is performed on. Thus, output No.
Constraints
- 1≤K<N≤2×105
- 1≤Ai≤N (1≤i≤N)
- All input values are integers.
样例 1 解释:
例如,若选择 2 作为 i,则 (A2,A3,A4,A5,A6,A7)=(4,1,4,2,1,3) 将被替换为 (1,1,2,3,4,4)。操作后,数组 A 变为 (1,1,1,2,3,4,4,5,6),满足题目条件。
因此,输出 Yes。
样例 2 解释:
K=1,因此无论对哪个 i 执行该操作,A 均不发生变化。故输出 No。
约束条件
- 1≤K<N≤2×105
- 1≤Ai≤N (1≤i≤N)
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?