CF56B.Spoilt Permutation

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order. That is, he took a certain segment [l, r] and reversed it. At that the segment's endpoints did not coincide. For example, if n = 8, then initially Vasya's coins were kept in the order 1 2 3 4 5 6 7 8. If Vasya's younger brother chose the segment [2, 6], then after the reversal the coin order will change to 1 6 5 4 3 2 7 8. Vasya suspects that someone else could have spoilt the permutation after his brother. Help him to find that out. Check if the given permutation can be obtained from the permutation 1 2 ... n using exactly one segment reversal. If it is possible, find the segment itself.

瓦西娅收集硬币:他恰好拥有从 11 到 nn 的每一年各一枚硬币。自然地,瓦西娅将所有硬币按其发行年份的顺序保存在自己的收藏中。某次,瓦西娅的弟弟做了一次改动——他取出了所有发行年份在 ll 到 rr(含端点)之间的硬币,并将它们的顺序完全反转。也就是说,他选取了某个区间 [l, r][l,\,r] 并对该区间进行翻转。此时该区间的两个端点不重合。例如,若 n=8n = 8,则瓦西娅最初的硬币顺序为 1 2 3 4 5 6 7 8;若弟弟选取区间 [2, 6][2,\,6],则翻转后硬币顺序变为 1 6 5 4 3 2 7 8。瓦西娅怀疑,在弟弟操作之后,可能还有其他人篡改了排列。请帮助他查明此事:判断给定的排列是否能通过对初始排列 1 2 ... n 恰好执行一次区间翻转操作而得到。若可以,请找出该翻转区间。

输入格式

The first line contains an integer n (1 ≤ n ≤ 1000) which is the number of coins in Vasya's collection. The second line contains space-separated n integers which are the spoilt sequence of coins. It is guaranteed that the given sequence is a permutation, i.e. it contains only integers from 1 to n, and every number is used exactly 1 time.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000),表示瓦西娅收藏的硬币数量。
第二行包含 nn 个用空格分隔的整数,表示损坏的硬币序列。题目保证该序列是一个排列,即它仅包含从 11 到 nn 的整数,且每个数字恰好出现一次。

输出格式

If it is impossible to obtain the given permutation from the original one in exactly one action, print 0 0. Otherwise, print two numbers l r (1 ≤ l < r ≤ n) which are the endpoints of the segment that needs to be reversed to obtain from permutation 1 2 ... n the given one.

如果无法通过恰好一次操作从原始排列得到给定排列,则输出 0 0。否则,输出两个数 ll 和 rr(满足 1 ≤ l < r ≤ n1 ≤ l < r ≤ n),表示需要翻转的区间端点,使得对排列 1 2 … n1\ 2\ \dots\ n 执行该区间翻转操作后,即可得到给定排列。

输入输出样例

  • 输入#1

    8
    1 6 5 4 3 2 7 8

    输出#1

    2 6
  • 输入#2

    4
    2 3 4 1

    输出#2

    0 0
  • 输入#3

    4
    1 2 3 4

    输出#3

    0 0

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

首页