#P15103. [ICPC 2025 LAC] Infinite Arrays
[ICPC 2025 LAC] Infinite Arrays
题目描述
A subarray of an array is a contiguous sequence of elements taken from . For example, if , then , , the empty array and the whole array are subarrays of (among others), while and are not subarrays of .
We also define as the array obtained by the concatenation of copies of the array . For example, if then , and .
In this problem you are given an array containing no repeated numbers, and you have to process a sequence of events that occur in order. The events can be of three types:
- Delete: a number present in must be deleted. For example, if and the number has to be deleted, once the event is processed will become .
- Insert: a number not present in must be inserted into before some other number present in . For example, if and the number must be inserted before the number , once the event is processed will become .
- Query: the length of the longest common subarray between and must be computed, where is an array given in the query. For example, if and , then the longest common subarray between and is , so the answer to the query is .
Are you ready for this challenge?
输入格式
The first line contains an integer () indicating the initial length of .
The second line contains different integers ( for ).
The third line contains an integer () representing the number of events that need to be processed.
Each of the next lines describes an event, in the order they must be processed. The content of the line depends on the event, as follows:
- Delete: the line contains the character “-” (minus sign) and an integer (, and ), denoting that must be deleted from . It is guaranteed that after the removal does not become empty.
- Insert: the line contains the character “+” (plus sign) and two integers and (, , and ), denoting that must be inserted into immediately to the left of .
- Query: the line contains the character “?” (question mark), a positive integer , and integers ( for ), indicating that the length of the longest common subarray between and must be computed. It is guaranteed that the input contains at least one query, and the sum of across all the queries is at most .
输出格式
Output a line for each query, with an integer indicating the length of the longest common subarray between and , or the character “*” (asterisk) if the length of the longest common subarray is larger than .
4
1 2 3 4
10
? 2 3 2
? 3 99 99 99
- 1
- 4
? 2 3 3
? 3 4 1 4
+ 64 3
+ 1 2
? 4 1 2 64 3
? 4 1 3 64 2
2
0
1
0
*
1
1
217
1
? 1 314
0