QOJ.ac

QOJ

Limite de temps : 8 s Limite de mémoire : 2048 MB Points totaux : 100

#11282. SMV CC-64 "Viper

Statistiques

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 $a_{i+1} = b_{a_i}$ for all $l' \le i < r'$, and there exists some $i$ such that $l' \le i \le r'$ and $a_i = x$. Output the maximum value of $r' - l' + 1$ satisfying these conditions; if no such subsegment exists, output $0$.

Input

The first line contains two integers $n$ and $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.

All input values are integers.

Output

For each query operation, output one 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

Subtasks

Idea: s_r_f, Solution: ccz181078, Code: ccz181078, Data: ccz181078

For $100\%$ of the data:

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

$1 \le a_i \le n$;

$1 \le b_i \le n$, and 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$.

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.