CF252B.Unsorting Array
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.
Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions:
- _a_1 ≤ _a_2 ≤ ... ≤ a__n;
- _a_1 ≥ _a_2 ≥ ... ≥ a__n.
Help Petya find the two required positions to swap or else say that they do not exist.
小Petya非常喜欢整数数组。最近,他的妈妈送给他一个包含 n 个元素的此类数组。Petya 现在想知道:他能否交换数组中任意两个互不相等的整数,使得该数组变得未排序。请注意,即使相等的整数位于数组中不同的位置,Petya 也不能交换它们。此外请注意,即使原始数组已经满足“未排序”的要求,Petya 也必须交换某两个整数。
一个包含 n 个元素的数组 a(数组元素下标从 1 开始)被称为已排序,当且仅当它满足以下两个条件之一:
- a1 ≤ a2 ≤ … ≤ an;
- a1 ≥ a2 ≥ … ≥ an。
请帮助 Petya 找出需要交换的两个位置;若不存在满足要求的交换,则说明其不存在。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n non-negative space-separated integers _a_1, _a_2, ..., a__n — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.
第一行包含一个整数 n(1≤n≤105)。第二行包含 n 个非负整数 a1, a2, …, an,以空格分隔——这些是佩佳的母亲送给他的数组的元素。输入中的所有整数均不超过 109。
输出格式
If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.
如果存在一对位置,使得交换这两个位置上的元素后数组变为无序,则输出这两个位置的编号(用空格分隔)。如果存在多对这样的位置,输出其中任意一对即可。如果不存在这样的位置对,则输出 -1。数组中的位置编号为从 1 到 n 的整数。
输入输出样例
输入#1
1 1
输出#1
-1
输入#2
2 1 2
输出#2
-1
输入#3
4 1 2 3 4
输出#3
1 2
输入#4
3 1 1 1
输出#4
-1
说明/提示
In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.
在前两个样例中,显然不存在满足要求的数对。
在第三个样例中,你可以交换前两个元素。交换后,数组将变为:2 1 3 4。该数组是未排序的。
输入解题思路,AI测评打分。不知道怎么写?