#P112. [TFXOI Round 1] 过往与现实之历史
[TFXOI Round 1] 过往与现实之历史
Source
This problem is proposed by . All rights reserved.
Problem Source: https://www.luogu.com.cn/problem/T565374
Problem Background
Time and space intertwine chaotically, where "deities" blend with illusions.
Problem Description
You are given a sequence consisting of distinct integers.
There are modification operations, each inserting all numbers from the original sequence's interval at the end of the current sequence.
Then, there are queries. Each query asks for the maximum length of a "good sequence" starting with the number on the interval inserted in the -th operation.
Note that all queries are performed after all insertions are completed.
A "good sequence" satisfies that the count of every number in is .
Input Format
The first line contains four integers .
The second line contains integers .
The next lines each contain two integers .
The following lines each contain two integers .
Output Format
Output lines, each containing one integer as the answer.
Samples
4 1 2 1
1 2 3 4
1 2
2 4
0 1
4
8 2 4 2
1 2 3 4 5 6 7 8
1 5
2 8
6 8
3 6
1 1
0 6
15
15
3 1 1 1
76546 39549 18452
1 1
0 18452
2
Sample 1 Explanation
- Initial sequence: .
- After the first operation: .
- After the second operation: .
Sample 2 Explanation
- Initial sequence: .
- After the first operation: .
- Final sequence: $S_4= \{1,2,3,4,5,6,7,8,1,2,3,4,5,2,3,4,5,6,7,8,6,7,8,3,4,5,6\}$.
Data Range
This problem uses bundled tests.
The problem is slightly time-sensitive, so please optimize your code for efficiency.
For all data:
- .
- .
- .
- .
| Subtask ID | Memory Limit | Points | ||||
|---|---|---|---|---|---|---|
| MB | ||||||
| MB | ||||||
| MB | ||||||