Big Data Permutation
시간 제한15초메모리 제한2048 MB
순열 b가 정한 '다음 수' 규칙 아래에서 수열 a를 갱신하며, 주어진 구간 안에 x를 포함하면서 규칙을 만족하는 가장 긴 연속 부분구간의 길이를 묻는다.
문제
You are given a sequence and a permutation . Process operations of the following form:
- Modification operation: given and , change into .
- Query operation: given , , and , find the longest sub-interval within the interval (formally, ) such that, for , we have , and additionally, there exists an such that and . You only need to output the maximum length of such sub-interval (formally, ); if there is none, output .
입력
The first line of input contains two integers and ().
The second line contains integers ().
The third line contains integers (; all are distinct).
Each of the next lines consists of integers and has either the form "1~$x$~$y$" for a modification operation or the form "2~$\ell$~$r$~$x$" for a query operation (; ).
You may assume that there is at least one query operation.
출력
For each query operation, output one line with the corresponding maximum length.