Mountain
InterviewTime limit1sMemory limit1024 MB
Count the contiguous subarrays that never decrease before a peak and never increase after it, with N up to 500000.
- Level
Medium5 of 10
- Topics
- Array, Two pointers
- Solved
- No attempts yet
Problem
Onjo likes climbing mountains. So Onjo wants to find as many mountain shapes as possible in a sequence of length .
Problem
Take a contiguous subsequence of . It is a mountain shape if there is an integer such that holds.
Help Onjo. Given the sequence , count the contiguous subsequences of that are mountain shaped.
Input
The first line contains the length of the sequence .
The second line contains integers separated by spaces.
Output
Print the number of contiguous subsequences of that are mountain shaped.
Constraints
For each (), .