CF451B.Sort the Array

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.

Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.

作为一名程序员,你非常喜爱数组。在你的生日时,朋友们送给你一个由 nn 个互不相同的整数构成的数组 aa。

不幸的是,数组 aa 的长度太小了。你想要一个更大的数组!朋友们同意送你一个更大的数组,但前提是:你必须正确回答如下问题——是否可以通过恰好反转数组 aa 中一个连续子段(segment),使得数组 aa 变为升序排列?关于“子段”(segment)和“反转”(reversing)的定义,请参见文末说明。

输入格式

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.

The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109).

输入的第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)—— 数组 aa 的大小。

第二行包含 nn 个互不相同的、以空格分隔的整数:a[1], a[2], …, a[n]a[1],\,a[2],\,\dots,\,a[n](1 ≤ a[i] ≤ 1091 \leq a[i] \leq 10^9)。

输出格式

Print "yes" or "no" (without quotes), depending on the answer.

If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.

根据答案输出 "yes" 或 "no"(不带引号)。

如果答案为 "yes",则还需输出两个用空格分隔的整数,表示待翻转区间的起始和结束下标(起始下标不得大于结束下标)。若存在多种选择方式,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    3 2 1

    输出#1

    yes
    1 3
  • 输入#2

    4
    2 1 3 4

    输出#2

    yes
    1 2
  • 输入#3

    4
    3 1 2 4

    输出#3

    no
  • 输入#4

    2
    1 2

    输出#4

    yes
    1 1

说明/提示

Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.

Sample 3. No segment can be reversed such that the array will be sorted.

Definitions

A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].

If you have an array a of size n and you reverse its segment [l, r], the array will become:

a[1], a[2], ..., a[l - 2], a[l - 1], a[r], a[r - 1], ..., a[l + 1], a[l], a[r + 1], a[r + 2], ..., a[n - 1], a[n].

样例 1:你可以将整个数组反转,得到 [1, 2, 3],该数组是有序的。

样例 3:不存在任何子段,使得将其反转后整个数组变为有序。

定义

数组 a 的一个子段 [l, r] 是指序列 a[l], a[l + 1], ..., a[r]。

若有一个大小为 n 的数组 a,将其子段 [l, r] 反转,则数组将变为:

a[1], a[2], ..., a[l - 2], a[l - 1], a[r], a[r - 1], ..., a[l + 1], a[l], a[r + 1], a[r + 2], ..., a[n - 1], a[n]。

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

首页