Logo
(追記) (追記ここまで)

33261번 - Big Data Permutation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
15 초 2048 MB0000.000%

문제

You are given a sequence $a_1, \ldots, a_n$ and a permutation $b_1, \ldots, b_n$. Process $m$ operations of the following form:

  • Modification operation: given $x$ and $y,ドル change $a_x$ into $y$.
  • Query operation: given $\ell,ドル $r,ドル and $x,ドル find the longest sub-interval $[\ell', r']$ within the interval $[\ell, r]$ (formally, $\ell \le \ell' \le r' \le r$) such that, for $\ell' \le j < r',ドル we have $a_{j + 1} = b_{a_j},ドル and additionally, there exists an $i$ such that $\ell' \le i \le r'$ and $a_i = x$. You only need to output the maximum length of such sub-interval (formally, $r' - \ell' + 1$); if there is none, output 0ドル$.

입력

The first line of input contains two integers $n$ and $m$ (1ドル \le n, m \le 10^6$).

The second line contains $n$ integers $a_1, \ldots, a_n$ (1ドル \le a_i \le n$).

The third line contains $n$ integers $b_1, \ldots, b_n$ (1ドル \le b_i \le n$; all $b_i$ are distinct).

Each of the next $m$ 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ドル \le x, y \le n$; 1ドル \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

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
1
0
1
1
3
2
1
0

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 3: THird roUnd B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /