#P5604. 小 O 与排列

小 O 与排列

Description

Little O has a permutation pp of length nn. His good friend euei\texttt{euei} has a sequence aa of length nn, with values in [1,n][1, n].

One day, Little O suddenly wondered whether there exists a pair of indices i,ji, j such that li,jrl \le i, j \le r and pai=ajp_{a_i} = a_j. He solved this problem easily. However, euei\texttt{euei} sometimes modifies the value at some position in this sequence, and also asks the above question for many different pairs l,rl, r. Now Little O does not know how to handle it.

Can you, the smart one, help Little O solve this problem?

Input Format

The first line contains two positive integers n,mn, m, where mm is the total number of modifications and queries.

The second line contains nn positive integers p1,p2,,pnp_1, p_2, \cdots, p_n, representing the permutation pp.

The third line contains nn positive integers a1,a2,,ana_1, a_2, \cdots, a_n, representing the initial sequence aa.

The next mm lines each contain three positive integers, in one of the following two formats:

  • 1 i v, meaning set aia_i to vv.
  • 2 l r, meaning query whether there exists a pair of indices i,ji, j such that li,jrl \le i, j \le r and pai=ajp_{a_i} = a_j.

Output Format

For each query, if such a pair exists, output Yes; otherwise output No.

3 4
3 1 2
2 2 1
2 2 3
1 2 3
1 3 3
2 2 3
Yes
No

Hint

Hint

The input size is large, so please use a fast input method.

Explanation of the samples

For the first query, the pair 2,32, 3 satisfies the requirement.

For the second query, no pair satisfies the requirement.

Constraints

This problem has 55 subtasks. You must pass all test points within a subtask to get the score for that subtask.

For all testdata, 1n,m5×1051 \le n,m \le 5\times 10^5, 1ai,i,v,l,rn1 \le a_i, i, v, l, r \le n, piip_i \neq i.

# Score n,mn, m Special Properties Time Limit
1 7 300\leqslant 300 1s\text{1s}
2 23 2000\leqslant 2000
3 15 No 1 operations 3s\text{3s}
4 In each query, sequence aa is a permutation
5 40

Blank entries in the table mean there are no special restrictions for that item.

Translated by ChatGPT 5