#P4224. [清华集训 2017] 简单数据结构
[清华集训 2017] 简单数据结构
Description
After IOI 2018 comes the interview for the "Yao Class". But you, because you dislike physics and want to become an entrepreneur like Steve Jobs, are successfully kicked back to the CS Department.
In the blink of an eye, the clock points to 2019, sophomore year, early December, finals week.
You had long heard seniors say that the midterm exam for Data Structures is hard, unfriendly to competitive programmers, and even training team members cannot finish the paper.
You sneer. Hmph, as an IOI gold medalist, what’s so hard about this exam.
In two hours, you read all content of the first five chapters of the solution manual and can recite it backwards.
In one hour, you read a 500-page handout and remember it vividly.
In ten minutes, you bike to the exam room. Confidently, you bring only a pen, even though it’s an open-book exam.
Now, you unfold the legendary god-tier paper, take a deep breath, and see—
Given a sequence of length , . If a subsequence of satisfies:
∀,|
then we call an "increasing multiple subsequence" of .
Now there is a sequence of length initialized as , and there are operations on . You are required to implement the following four operations:
0 x: Insert a number at the left end of sequence .
1 x: Insert a number at the right end of sequence .
2: Remove one number from the left end of sequence .
3: Remove one number from the right end of sequence .
After initializing sequence and after each operation, compute the length of the longest increasing multiple subsequence in the current , and the number of distinct starting numbers among all increasing multiple subsequences of length . Output and .
To drastically reduce the difficulty, it is guaranteed that the sequence is non-empty at any time, its elements are all distinct, and all elements are positive integers between . Each same number will be inserted at most times.
Input Format
The first line of input contains three positive integers as described above. It is guaranteed that , , .
The second line contains positive integers, which are . It is guaranteed that , and all elements in sequence are distinct.
Then there are lines. Each line is in one of the following formats: 0 x, or 1 x, or 2, or 3, with meanings as described above.
Output Format
Output lines. After initialization and after each operation on sequence , output the length of the longest increasing multiple subsequence in and the number of distinct starting numbers among all increasing multiple subsequences of length , separated by a single space.
5 10 10
1 2 5 9 10
2
1 7
3
3
0 8
3
2
1 8
3
0 3
3 1
2 2
2 2
2 2
1 3
1 4
1 3
1 2
2 1
1 2
1 3
Hint
Sample explanation.
In the table, different longest increasing subsequences are separated by //.

For all testdata, , , , , .
The table below shows some special constraints for certain data points. Here, “only 1” means only operations of the form 1 x; similar statements apply to the others.

Postscript.
The meme “fight for two hours, score forty or fifty” has taken over your social feed:
“Ah, I feel like my life is complete.”
“I hope... I can really get forty or fifty.”
“I finished the exam... Finished... Doomed.”
“I used to think it was a joke, turns out I was still naïve.”
You sneer. You hand in the paper half an hour early, naturally thinking: Data Structures, full score, as expected.
Translated by ChatGPT 5
京公网安备 11011102002149号