[Login|Register]
Problems

Status

Rank

Problem 1266
Sequence Again
Time Limit: 1000ms
Memory Limit: 65536kb
Description
First we need to define a kind of "special sequence". A special sequence is defined as follows: if and only if it contains exactly 1, 2, 3...N and N is the length of the sequence. So {4, 2, 1, 3} is a "special sequence", but {1, 2, 2} not,neither is{1,2,4}.
Given a sequence in length of N, we all know it has many continuous subsequences. As you guess, some subsequences are "special sequence".
Now your task is to find the longest "special sequence" among all the continuous subsequences.
Input
The first line, an integer T, representing T test cases below. (T<=100).
For each test case, an integer N (1<=N<=20000) comes first, indicating the length of the sequence, followed by N positive numbers between 1 and N.
Output
For each case, output the longest "special sequence".
Sample Input
3
5
1 2 3 4 5
4
1 2 2 3
4
2 3 4 4
Sample Output
5
2
0
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.4ms with 1 query(s).