Infinite Arrays
시간 제한1.5초메모리 제한2048 MB
원소의 삭제와 삽입으로 변하는 순열 P를 관리하면서, 질의로 주어지는 배열 A에 대해 P와 A를 무한히 반복한 배열의 최장 공통 부분배열 길이를 10^18을 넘으면 *로 출력한다.
문제
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 .