Big Data Permutation

시간 제한15초메모리 제한2048 MB

요약
순열 b가 정한 '다음 수' 규칙 아래에서 수열 a를 갱신하며, 주어진 구간 안에 x를 포함하면서 규칙을 만족하는 가장 긴 연속 부분구간의 길이를 묻는다.
난이도

어려움10점 중 10점

유형
세그먼트 트리, 동적 계획법, 행렬
정답자
아직 제출이 없습니다

문제

You are given a sequence a_1,…,a_na\_1, \ldots, a\_n and a permutation b_1,…,b_nb\_1, \ldots, b\_n. Process mm operations of the following form:

  • Modification operation: given xx and yy, change a_xa\_x into yy.
  • Query operation: given ℓ\ell, rr, and xx, find the longest sub-interval \[ℓ′,r′]\[\ell', r'] within the interval \[ℓ,r]\[\ell, r] (formally, ℓ≤ℓ′≤r′≤r\ell \le \ell' \le r' \le r) such that, for ℓ′≤j<r′\ell' \le j < r', we have a_j+1=b_a_ja\_{j + 1} = b\_{a\_j}, and additionally, there exists an ii such that ℓ′≤i≤r′\ell' \le i \le r' and a_i=xa\_i = x. You only need to output the maximum length of such sub-interval (formally, r′−ℓ′+1r' - \ell' + 1); if there is none, output 00.

입력

The first line of input contains two integers nn and mm (1≤n,m≤1061 \le n, m \le 10^6).

The second line contains nn integers a_1,…,a_na\_1, \ldots, a\_n (1≤a_i≤n1 \le a\_i \le n).

The third line contains nn integers b_1,…,b_nb\_1, \ldots, b\_n (1≤b_i≤n1 \le b\_i \le n; all b_ib\_i are distinct).

Each of the next mm 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 (1≤x,y≤n1 \le x, y \le n; 1≤ℓ≤r≤n1 \le \ell \le r \le n).

You may assume that there is at least one query operation.

출력

For each query operation, output one line with the corresponding maximum length.

예제1

  1. 예제 1

    입력
    8 10
    1 4 7 3 8 2 4 7
    5 4 8 7 1 6 3 2
    2 6 6 2
    2 8 8 7
    1 4 3
    2 6 8 3
    2 4 4 3
    2 4 4 3
    2 6 8 4
    2 5 6 2
    2 1 8 1
    2 1 1 6
    
    예상 출력
    1
    1
    0
    1
    1
    3
    2
    1
    0