CF27C.Unordered Subsequence

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.

A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

如果一个序列是非递减的或非递增的,则称该序列为有序的。例如,序列 [3, 1, 1, 0] 和 [1, 2, 3, 100] 是有序的,但序列 [1, 3, 3, 1] 不是有序的。你将得到一个数字序列,请找出其中最短的无序子序列。

子序列是指通过从原序列中删除零个或多个元素(不改变剩余元素的相对顺序)而得到的序列。

输入格式

The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value.

输入的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。第二行包含 nn 个以空格分隔的整数——给定的序列。该序列中的所有数的绝对值均不超过 10610^6。

输出格式

If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them.

如果给定序列不包含任何无序子序列,则输出 0;否则,输出最短此类子序列的长度 kk,然后输出 kk 个取值范围在 [1..n][1..n] 内的整数——即该子序列中各元素的下标。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    67 499 600 42 23

    输出#1

    3
    1 3 5
  • 输入#2

    3
    1 2 3

    输出#2

    0
  • 输入#3

    3
    2 3 1

    输出#3

    3
    1 2 3

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

首页