#P4563. [JXOI2018] 守卫
[JXOI2018] 守卫
Description
On this day she goes mountain climbing. For her safety, her father hires some bodyguards to stay fixed at certain positions on the mountain to monitor Jiutiao Kelian in real time and thus protect her.
Specifically, a mountain can be described as a polyline, and the area below the polyline is rock. This polyline has vertices, and there is a pavilion at each vertex. The -th vertex has coordinates . Jiutiao Kelian can only play at pavilions, and the bodyguards also only monitor at pavilions.
Due to technical reasons, a guard can only monitor all pavilions he can see whose x-coordinate does not exceed his own position. We say a guard can see a pavilion if and only if the segment connecting his own pavilion and does not pass through any rock. In particular, if this segment happens to pass exactly through any pavilion other than and , then we consider that the guard cannot see Kelian.
Hiring guards is expensive, so Kelian’s father wants as few guards as possible.
Kelian’s father also wants a detailed hiring plan. He knows some pavilions may be under maintenance. He wants to compute, for all : if it is known in advance that only the pavilions in the interval can be used for playing (and monitoring), what is the minimum number of guards needed so that every pavilion in is monitored.
Kelian’s father has already obtained a result, and he hopes you can verify whether his result is correct.
Input Format
The first line contains an integer denoting the number of pavilions.
The second line contains integers, where the -th integer means the -th pavilion is at .
Output Format
For all , compute the minimum number of guards needed if it is known in advance that Kelian will only play at pavilions in , so that every pavilion in is monitored. Since the output would be too large, Kelian’s father only asks you to output the XOR of the answers for all .
3
2 3 1
3
Hint
Sample Explanation:
- If , the answer is .
- If , , then the answer is , and two guards are needed at and to monitor Kelian.
Constraints:
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号