luogu#P8904. [USACO22DEC] Mountains G
[USACO22DEC] Mountains G
Problem Description
Along the edge of Farmer John’s farm, there are mountains arranged in a line at equal spacing. These mountains can be represented by a height array . For mountain , mountain is visible if there is no mountain strictly higher than the line of sight connecting the peaks of mountains and . Formally, for two mountains , if there does not exist such that and the point is above the line segment connecting and , then these two mountains can see each other.
You are given update operations, each of which increases the height of one mountain. After each update, output the number of unordered pairs of mountains that can see each other.
Input Format
The first line contains .
The second line contains heights (for each , ).
The third line contains .
Lines to each contain , where is the index of the mountain and is the amount by which its height increases. The input guarantees that the height of this mountain after the update does not exceed .
Output Format
Output lines, each containing the number of unordered pairs of mountains that can see each other after the corresponding update.
5
2 4 3 1 5
3
4 3
1 3
3 2
7
10
7
Hint
Sample 1 Explanation
Initially, the following pairs of mountains can see each other: , , , , , , for a total of pairs.
After the first update, the height of mountain becomes . This does not block any existing visibility, but it makes mountain able to see mountain , so the answer becomes .
After the second update, the height of mountain becomes . This does not block any existing visibility, but it makes mountain able to see mountains , , and , so the answer becomes .
After the third update, the height of mountain becomes . This blocks mountain from seeing mountain , and blocks mountain from seeing mountains and . At the same time, since this mountain could already see all other mountains, it does not make it see more mountains, so the answer becomes .
Test Point Properties
- Test points satisfy .
- Test points satisfy .
- Test points have no additional properties.
Translated by ChatGPT 5