#P8538. 「Wdoi-2」灵山之上神风起
「Wdoi-2」灵山之上神风起
Description
Brief Statement
You are given a positive integer sequence of length , satisfying for all .
Construct an undirected graph with nodes numbered from to using this sequence. For each :
- If , do nothing.
- If , add undirected edges from node to all nodes with indices smaller than .
- If , add undirected edges from node to all nodes with indices greater than .
Find the size of the maximum independent set of this graph.
A maximum independent set is a set of as many vertices as possible such that no two vertices in the set are directly connected by an edge in the original graph.
Original Statement
However, Kochiya Sanae (hereinafter referred to as Sanae) has an extremely high danmaku density, making it hard to keep up. Reimu had to find a way to reduce the amount of danmaku she needed to pay attention to.
After several rounds, she discovered that each time Sanae releases danmaku, she releases exactly bullets, numbered . Each bullet she releases corresponds to a divine power fluctuation. Thus, her divine power fluctuations can be abstracted as a positive integer sequence of length , . Since she is still inexperienced, she can only use three kinds of divine power, represented by . That is, , .
She found that Sanae’s three kinds of divine power act differently, specifically:
- When , she does nothing.
- When , Sanae makes the -th bullet establish divine power transfer channels to all bullets with indices smaller than .
- When , Sanae makes the -th bullet establish divine power transfer channels to all bullets with indices greater than .
Then, with various interactions and combinations of divine power, dense danmaku unfolds before Reimu’s eyes. Marisa, who is standing nearby, discovers that if they pick as many as possible bullets from these danmaku such that there is no directly connected divine power transfer channel between any pair of bullets, then this group of bullets will produce the “ability to cause miracles”, meaning they do not need to be paid attention to.
Since the “ability to cause miracles” can only be triggered once, Reimu and Marisa want to know: at most how many bullets can be ignored. They found you and hope you can help answer this question.
Input Format
- The first line contains a positive integer , indicating the total number of bullets.
- The second line contains positive integers . See the problem description for their meaning.
Output Format
- Output one positive integer in a single line, indicating the maximum number of bullets that can be ignored.
6
3 1 3 2 1 2
2
Hint
Sample Explanation
According to the statement, we can clearly construct the following graph. Edges for are shown in blue, and edges for are shown in red.
Obviously, choosing bullets (already filled in green) is the maximum. In fact, for this sample there is more than one valid selection plan, but there is no selection with more bullets.

Constraints
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|}\hline \textbf{Subtask} & \bm{n\le} & \textbf{Special Property} & \textbf{Score}\\\hline 1 & 10 & - & 20\\\hline 2 & 10^5 & \text{A} & 10\\\hline 3 & 10^5 & \text{B} & 30 \\\hline 4 & 10^5 & - & 40 \\\hline \end{array}$$- Special Property : all .
- Special Property : every is either or .
For of the testdata, , and .
Translated by ChatGPT 5
京公网安备 11011102002149号