Array Partition

0

0 votes
Medium
Problem

You have an array A of N integers A1,A2...AN.
startP and endP are 2 integers defined in array partition P, which
consists all the elements lying at positions [startP,startP+1...endP].
That is, partition P refers to subarray [AstartP,AstartP+1...AendP]
such that startP≤endP.
The value of partition is defined as maximum element present in the partition i.e. value(P)=maximum(AstartP,AstartP+1...AendP).

You have to find the total number of ways to divide array A into
sequence of partitions such that each element of A belongs to exactly one partition and value of each partition is not less than the value of next partition.

Formally, Suppose you divided array A into k partitions P1,P2...Pk for
some k≥1, then following conditions should be met:

  1.  startP1=1 and endPk=N.
  2.  startPi≤endPi for all i≤k.
  3.  startPi+1=endPi+1 for all i<k.
  4.  value(Pi)≥value(Pi+1) for all i<k.


You have to find out total number of ways to divide array A into such sequence of partitions.

INPUT:

  • First line of input consists of integer T denoting total number of testcases.
  • First line of each test case consists of an integer N. Next line consists of N integers A1,A2...AN.


Output:

  • Output the total number of ways to divide the given array into partitions. Since output can be large, print the total number of ways modulus 109+7.


Constraints:
1≤T≤20
1≤N≤105
1≤Ai≤105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Explanation

In first sample case, all the 4 possible partitions are [[3,2,1]], [[3], [2,1]], [[3,2], [1]], [[3], [2], [1]].


In second sample case, only 2 partitions are possible [[1,3,2]] and [[1,3], [2]].

Editor Image

?