Shubham and Subarrays

3

20 votes
Problem

You are given an array consisting of n integer numbers a1,a2..an. Two subarrays [l1 r1] (1l1r1n) and [l2 r2] (1l2r2n) are considered the same if they have the same "special set" of numbers. Output the number of distinct subarrays.
Note: A "special set" of numbers is a set of unique numbers sorted in increasing order.For example,the "special set" corresponding to the numbers [5,2,7,2,5,9] is [2,5,7,9].

Input Format
First line contains n denoting the number of array elements.
Second line contains n integers denoting a1,a2..an

Output Format
Output the required answer.

Constraints
1n1000
1ai1000

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

Special Set of numbers in subarray [1 1]: {1}
Special Set of numbers in subarray [2 2]: {1}
Special Set of numbers in subarray [3 3]: {2}
Special Set of numbers in subarray [1 2]: {1}
Special Set of numbers in subarray [1 3]: {1,2}
Special Set of numbers in subarray [2 3]: {1,2}
Thus the number of distinct subarrays are 3.

Editor Image

?