LPERMUT - Longest Permutation
You are given a sequence A of n integer numbers (1<=Ai<=n). A subsequence of A has the form Au, Au+1 ... , Av (1<=u<=v<=n). We are interested in subsequences that are permutations of 1, 2, .., k (k is the length of the subsequence).
Your task is to find the longest subsequence of this type.
Input
- Line 1: n (1<=n<=100000)
- Line 2: n numbers A1, A2, ... ,An (1<=Ai<=n)
Output
A single integer that is the length of the longest permutation
Example
Input: 5 4 1 3 1 2 Output: 3
hide comments
ZY:
2012-02-19 07:41:31
NlogN
|
|
Ravi Kiran:
2013-02-16 16:54:51
Very tight time limit.
|
|
Ripatti:
2010-07-24 10:12:59
My solution for test
|
|
Iqram Mahmud:
2010-05-25 07:23:11
3 1 2 ( at the end of the seq ) is a permutation of ( 1, 2, 3 ). |
|
Sai Kiran Reddy Jakka:
2010-05-23 11:48:29
I did not get the question .........how the outout is 3 for the example??? |
|
Wang Kainnan:
2009-05-29 14:14:20
hoho,finally ,wheather the solution is good depends on how it reads fast |
|
baichi:
2009-05-26 02:42:26
the monotone queue Last edit: 2009-05-26 02:43:17 |
Added by: | Jimmy |
Date: | 2006-02-20 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 VB.NET |
Resource: | A problem put forward by Mr Mircea Pasoi |