#P10210. [CTS2024] 水镜
[CTS2024] 水镜
Problem Description
Hint: At the end of the statement, we provide a brief and formal description.
City A is a rainy city with many mountain streams and springs. Because people love water, they built a large fountain in the center of the city.
In the fountain pool, there is a row of stone pillars, numbered from left to right as . The height of the -th pillar is . The pool contains water, and the water level is a positive real number. The -th pillar produces a reflection with height . If the pillar is above the water surface, the reflection is below the water surface; if the pillar is below the water surface, the reflection is above the water surface; if the top of the pillar is exactly on the water surface, then the reflection is also exactly on the water surface.
It is said that spring spirits live in the water. On every full moon night, they dance on the pillars, following these rules:
- A spring spirit can only stay on the top of a pillar, or on the top of the pillar’s reflection. That is, if the spirit is on pillar , its height can only be or .
- Each move, the spring spirit can only go to the adjacent pillar on the right (or the adjacent reflection).
- During the movement, the spirit’s height must be strictly increasing.
A spring spirit chooses a pillar (or its reflection) as the starting point, makes several moves, and then stops. Such a process is called a dance.
City A has a long rainy season. Because rainfall is irregular, the fountain’s water level may change many times, and the possible dance paths change as well. As a traveler from afar, you want to know how many dances can be made possible. Specifically, you need to count how many pairs () satisfy that there exists a water level such that, in a single dance, the spirit can start from the -th pillar (or its reflection) and reach the -th pillar (or its reflection).
Formal: Given a positive integer sequence of length , find the number of pairs that satisfy all of the following conditions:
- , and are integers.
- There exists a positive real number and a sequence of length such that all of the following hold:
- , let . Then . In particular, when , we have .
- .
Input Format
The first line contains a positive integer , representing the number of stone pillars.
The second line contains positive integers , representing the heights of the pillars.
Output Format
Output one line containing one integer, representing the number of pairs that satisfy the statement.
4
1 3 2 4
6
Hint
Explanation for Sample 1
All pairs are feasible.
For , you can choose , then the sequence is . Taking the sequence as satisfies all conditions.
Constraints
For all testdata, , .
| Subtask ID | Points | |
|---|---|---|
Translated by ChatGPT 5