409031: GYM103422 A MLCS

Memory Limit:64 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. MLCStime limit per test0.6 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

You are given an array $$$a$$$ of $$$n$$$ integers. A subsequence of $$$a$$$ can be obtained by keeping some (perhaps none, or all) elements of $$$a$$$, in the same order as in the original array. Formally, a subsequence $$$b$$$ of length $$$k$$$ can consist of $$$a[i_1],a[i_2] \ldots, a[i_k]$$$, if and only if $$$1 \le i_1 \lt i_2 \lt \ldots \lt i_k \le n$$$.

For example, if $$$a=[1,2,5,4,3]$$$, then $$$[$$$ $$$]$$$, $$$[1]$$$, or $$$[1,5,4]$$$ are subsequences of $$$a$$$, while $$$[6]$$$, $$$[1,1]$$$ or $$$[3,4,5]$$$ are not.

Unfortunately, not all subsequences are created equal, some being fancier than others. These fancy subsequences are also known as constant subsequences. A subsequence $$$b=$$$ $$$[$$$ $$$a[i_1],a[i_2],\ldots , a[i_k]$$$ $$$]$$$ is considered constant if $$$b[1]+1=b[2]+2= \ldots = b[k]+k$$$.

Find the maximum length $$$k$$$ of any constant subsequence of $$$a$$$, as well as the indices $$$i_1, i_2, \ldots, i_k$$$ coresponding to any maximal constant subsequence.

If there are multiple constant subsequences of length $$$k$$$, you may print any.

Input

The first line of input contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$) - the length of array $$$a$$$. The second line of input contains $$$n$$$ integers, the elements of array $$$a$$$ ($$$1 \le a_1, a_2, \ldots, a_n \le n$$$).

Output

Print the maximum length $$$k$$$ of any constant subsequence, followed by $$$k$$$ indices $$$i_1, i_2, \ldots, i_k$$$ coresponding to the elements of $$$a$$$ present in some constant subsequence of length $$$k$$$.

 
If there are multiple constant subsequences of length $$$k$$$, you may print any.Scoring
  • Subtask 1 (30 points): $$$n \le 5000$$$;
  • Subtask 2 (40 points): $$$5000 \lt n \le 10^5$$$;
  • Subtask 3 (30 points): $$$10^5 \lt n \le 10^6$$$;
ExampleInput
7
5 6 1 4 2 3 2
Output
4
1 4 6 7 
Note

The answer for the sample is $$$[a_1,a_4,a_6,a_7]=[5,4,3,2]$$$. $$$[5,4,3,2]$$$ is constant, since $$$5+1=4+2=3+3=2+4$$$.

加入题单

算法标签: