Counting Consecutive Ascending Subarrays
InterviewTime limit1sMemory limit1024 MB
Given a permutation A of length N, count the pairs (i, j) with i at most j where A_i through A_j are strictly increasing.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence of length . Every number in the sequence is a distinct integer from to . Count the pairs of integers that satisfy all of the following conditions.
- .
- From the -th number to the -th number of , the sequence is in ascending order. That is, for every integer with , .
Input
The first line contains the length of the sequence.
The next line contains the elements separated by spaces. ; are distinct integers.
Output
Print the number of pairs that satisfy the conditions.