AT_abc478_c.Sort Subarray

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a length-NN integer sequence A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N).

You will perform the following operation on AA exactly once.

  • Choose an integer ii between 11 and N−K+1N-K+1, inclusive. Sort Ai,Ai+1,…,Ai+K−1A _ i,A _ {i+1},\ldots,A _ {i+K-1} in ascending order. More formally, let B1,B2,…,BKB _ 1,B _ 2,\ldots,B _ K be Ai,Ai+1,…,Ai+K−1A _ i,A _ {i+1},\ldots,A _ {i+K-1} arranged in increasing order, and simultaneously replace Ai+j−1A _ {i+j-1} with BjB _ j for 1≤j≤K1\le j\le K.

Determine whether it is possible that, after this operation, AA is in ascending order, that is, Ai≤Ai+1A _ i\le A _ {i+1} holds for all 1≤i<N1\le i\lt N.

给你一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N)。

你将对 AA 恰好执行一次如下操作:

  • 选择一个整数 ii,满足 1≤i≤N−K+11 \le i \le N-K+1。将子数组 Ai,Ai+1,…,Ai+K−1A _ i,A _ {i+1},\ldots,A _ {i+K-1} 按升序排序。更准确地说,设 B1,B2,…,BKB _ 1,B _ 2,\ldots,B _ K 是 Ai,Ai+1,…,Ai+K−1A _ i,A _ {i+1},\ldots,A _ {i+K-1} 按升序排列后的结果,并同时将每个 Ai+j−1A _ {i+j-1} 替换为 BjB _ j(其中 1≤j≤K1 \le j \le K)。

判断:在执行该操作后,是否可能使 AA 成为升序序列,即对所有 1≤i<N1 \le i < N 均满足 Ai≤Ai+1A _ i \le A _ {i+1}。

输入格式

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

NN KK
A1A _ 1 A2A _ 2 …\ldots ANA _ N

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

NN KK
A1A _ 1 A2A _ 2 …\ldots ANA _ N

输出格式

If AA can be sorted in ascending order by performing the operation once, output Yes; otherwise, output No.

如果通过对 AA 执行一次该操作即可将其按升序排序,则输出 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 22 as ii, then (A2,A3,A4,A5,A6,A7)=(4,1,4,2,1,3)(A _ 2,A _ 3,A _ 4,A _ 5,A _ 6,A _ 7)=(4,1,4,2,1,3) is replaced with (1,1,2,3,4,4)(1,1,2,3,4,4). After the operation, AA is (1,1,1,2,3,4,4,5,6)(1,1,1,2,3,4,4,5,6), which satisfies the condition.

Thus, output Yes.

Sample 2 Explanation:
K=1K=1, so AA does not change regardless of which ii the operation is performed on. Thus, output No.

Constraints

  • 1≤K<N≤2×1051\le K\lt N\le2\times10 ^ 5
  • 1≤Ai≤N (1≤i≤N)1\le A _ i\le N\ (1\le i\le N)
  • All input values are integers.

样例 1 解释:
例如,若选择 22 作为 ii,则 (A2,A3,A4,A5,A6,A7)=(4,1,4,2,1,3)(A _ 2,A _ 3,A _ 4,A _ 5,A _ 6,A _ 7)=(4,1,4,2,1,3) 将被替换为 (1,1,2,3,4,4)(1,1,2,3,4,4)。操作后,数组 AA 变为 (1,1,1,2,3,4,4,5,6)(1,1,1,2,3,4,4,5,6),满足题目条件。

因此,输出 Yes。

样例 2 解释:
K=1K=1,因此无论对哪个 ii 执行该操作,AA 均不发生变化。故输出 No。

约束条件

  • 1≤K<N≤2×1051\le K\lt N\le2\times10 ^ 5
  • 1≤Ai≤N (1≤i≤N)1\le A _ i\le N\ (1\le i\le N)
  • 所有输入值均为整数。

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

首页