TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

"The daily maximum temperature reached 31°C for 10 consecutive days in August."
"Kuo has 10 strikeouts in each of 5 successive games."
"NTU has at least 2 teams qualified to World Finals in recent 5 years."

The above sentences are records that journalists would like to include in newspapers and magazines. These records share a common pattern: a time period, and the minimum value happened in that period. We would use (length, value) to represent a record, where length is the length of the time period, and value is the minimum value in that period.

However, not all records are interesting to the journalists, such as the following one:

"NTU has at least 1 team qualified to World Finals in recent 3 years"

Given that there is a (5,2) record, no journalist would like to report the (3,1) one.
Formally, a record (l1, v1) is not interesting if there is another record (l2, v2) satisfying one of the following criteria:


  • l2 > l1, v2 >= v1

  • l2 >= l1, v2 > v1


  • Given a time series (the value in each time unit),
    please help the journalists to identify the number of interesting records.

Input Format

The first line of the input contains an integer T, which is the number of test cases.

Each test case consists of two lines.
The first line has an integer n, indicating the number of time units in the series.
The second line has n integers a1,...,an, where ai denotes the value in the i-th time unit.
(1 <= n <= 200000, |ai| < 231)

Output Format

Please output one integer for each test case, indicating the number of interesting records.
A record may occur more than once in the series, but it should be counted only once.

Sample Input 1

2
8
1 3 7 5 8 2 4 6
4
8 6 9 3

Sample Output 1

5
3

Hints

The interesting records in the first sample are: (8,1), (7,2), (4,3), (3,5) and (1,8).
The interesting records in the second sample are: (4,3), (3,6) and (1,9).

Problem Source

Migrated from old NTUJ.

Ferng

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 4000 65536 200