#FT0000212. Chụp ảnh các ngôi sao (Starry Landscape Photo)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chụp ảnh các ngôi sao (Starry Landscape Photo)
Starry Landscape Photo
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
On planet AtCoder, stars are arranged in a line from east to west. Their positions are numbered through , starting with the easternmost star.
All stars have distinct brightness ranks. The star at position has rank : rank is the brightest. The sequence is a permutation of .
Takahashi takes a photograph using the following two steps:
- Choose with . Only stars at consecutive positions through fit into the frame.
- Choose with . Among the framed stars, capture exactly those with brightness rank at most , namely .
The photograph must not be empty. Two photographs are considered identical if they show the same set of stars, even if their choices of differ.
Count the distinct nonempty sets of stars that can appear in a photograph.
Input
- The first line contains the integer , the number of stars.
- The second line contains exactly integers , in east-to-west order. They form a permutation of through .
Output
Print one integer: the number of distinct nonempty sets of stars that can be photographed. Do not reduce the answer modulo any number.
Subtasks
- Subtask 1 (20 points): ; for each ; for all .
- Subtask 2 (30 points): ; for each ; for all .
- Subtask 3 (50 points): ; for each ; for all .
Examples
Example 1
Input
4
3 1 4 2
Output
12
Explanation
The brightness ranks from east to west are . Group photographed sets by their largest rank: rank contributes set; rank contributes sets; rank contributes sets; and rank contributes sets. In total, distinct nonempty sets can be photographed. For example, captures the stars of ranks and .
Example 2
Input
7
1 2 3 4 5 6 7
Output
28
Explanation
Ranks increase from to in east-to-west order. For each possible largest rank , there are exactly obtainable sets whose largest rank is , corresponding to consecutive segments ending at position . Hence the answer is .