QOJ.ac

QOJ

时间限制: 15 s 内存限制: 2048 MB 总分: 100

#4316. pmrmscxip

统计

Given a sequence $a_1, \dots, a_n$ and a permutation $b_1, \dots, b_n$, there are $m$ operations:

Modification: Given $x, y$, change $a_x$ to $y$.

Query: Given $l, r, x$, find the longest subsegment $[l', r']$ within $[l, r]$ (i.e., $l \le l' \le r' \le r$) such that for all $l' \le i < r'$, $a_{i+1} = b_{a_i}$, and there exists some $i$ such that $l' \le i \le r'$ and $a_i = x$. Output the maximum value of $r' - l' + 1$, or $0$ if no such subsegment exists.

Input

The first line contains two integers $n, m$.

The second line contains $n$ integers representing $a_1, \dots, a_n$.

The third line contains $n$ integers representing $b_1, \dots, b_n$.

The next $m$ lines each contain either $1, x, y$ or $2, l, r, x$, representing a modification operation or a query operation, respectively.

$1 \le n, m \le 10^6$.

$1 \le a_i \le n$.

$1 \le b_i \le n$, where all $b_i$ are distinct.

For modification operations, $1 \le x, y \le n$.

For query operations, $1 \le l \le r \le n$ and $1 \le x \le n$.

All input values are integers.

Output

For each query operation, output a single line containing the corresponding answer.

Examples

Input 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

Output 1

1
1
0
1
1
3
2
1
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.