Sort SubarrayAI (CI翻译)
Problem Statement
You are given a length-$N$ integer sequence $A=(A _ 1,A _ 2,\ldots,A _ N)$.
You will perform the following operation on $A$ exactly once.
- Choose an integer
$i$between$1$and$N-K+1$, inclusive. Sort$A _ i,A _ {i+1},\ldots,A _ {i+K-1}$in ascending order. More formally, let$B _ 1,B _ 2,\ldots,B _ K$be$A _ i,A _ {i+1},\ldots,A _ {i+K-1}$arranged in increasing order, and simultaneously replace$A _ {i+j-1}$with$B _ j$for$1\le j\le K$.
Determine whether it is possible that, after this operation, $A$ is in ascending order, that is, $A _ i\le A _ {i+1}$ holds for all $1\le i\lt N$.
Constraints
$1\le K\lt N\le2\times10 ^ 5$$1\le A _ i\le N\ (1\le i\le N)$- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K
A _ 1 A _ 2 \ldots A _ N
Output
If $A$ can be sorted in ascending order by performing the operation once, output Yes; otherwise, output No.
{"titleZh":"排序子数组","bodyZh":"## 题目描述\n\n给定一个长度为 $N$ 的整数序列 $A=(A _ 1,A _ 2,\ldots,A _ N)$。\n\n你需要对 $A$ 恰好执行一次以下操作。\n\n- 选择一个满足 $1\\le i\\le N-K+1$ 的整数 $i$,将 $A _ i,A _ {i+1},\\ldots,A _ {i+K-1}$ 按升序排序。更正式地,设 $B _ 1,B _ 2,\\ldots,B _ K$ 是将 $A _ i,A _ {i+1},\\ldots,A _ {i+K-1}$ 按递增顺序排列后得到的序列,并同时对所有 $1\\le j\\le K$,将 $A _ {i+j-1}$ 替换为 $B _ j$。\n\n判断执行该操作后,$A$ 是否可能按升序排列,也就是说,对于所有 $1\\le i\\lt N$,是否满足 $A _ i\\le A _ {i+1}$。\n\n## 约束条件\n\n- $1\\le K\\lt N\\le2\\times10 ^ 5$\n- $1\\le A _ i\\le N\\ (1\\le i\\le N)$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入中按以下格式给出:\n\n``\nN K\nA _ 1 A _ 2 \\ldots A _ N\n。"}AI (CI翻译)\n\n## 输出格式\n\n如果恰好执行一次该操作后可以将 $A$ 按升序排列,输出 Yes;否则,输出 No
样例
9 6
1 4 1 4 2 1 3 5 6
Yes
3 1
3 2 1
No
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
Yes
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。