RMQ 2
Problem
Given two sequences of length N, A and B. First, the i item in the sequence A is ai, and the i item in the sequence B is bi.
Since a total of Q of statements of the following format are given, create a program that processes in the given order.
Each statement is represented by three integers x,y,z.
- Set the value of the y item in the sequence A to z. (When x=1)
- Set the value of the y item in the sequence B to z. (When x=2)
- Find and report the smallest value in the z item from the y item in the sequence A. (When x=3)
- Find and report the smallest value in the z item from the y item in the sequence B. (When x=4)
- Change the sequence A to be exactly the same as the sequence B. (When x=5)
- Change the sequence B to be exactly the same as the sequence A. (When x=6)
Constraints
The input satisfies the following conditions.
- 2 leN le2 times105
- 2 leQ le2 times105
- 1 leai le109
- 1 lebi le109
- 1 lexi le6
- 1 leyi leN (when 1 lexi le4)
- yi=−1 (when xi=5,6)
- 1 lezi le109 (when xi=1,2)
- yi lezi leN (when xi=3,4)
- zi=−1 (when xi=5,6)
- All inputs are integers
Input
The input is given in the following format.
N
a1 a2 ... aN
b1 b2 ... bN
Q
x1 y1 z1
x2 y2 z2
...
xQ yQ zQ
Output
Every time a statement of x=3 or x=4 is given by input, the found value is output on one line.
Example
Input
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
Output
7
2
2
8
1
input satisfies the following conditions.
- 2 leN le2 times105
- 2 leQ le2 times105
- 1 leai le109
- 1 lebi le109
- 1 lexi le6
- 1 leyi leN (when 1 lexi le4)
- yi=−1 (when xi=5,6)
- 1 lezi le109 (when xi=1,2)
- yi lezi leN (when xi=3,4)
- zi=−1 (when xi=5,6)
- All inputs are integers
Input
The input is given in the following format.
N
a1 a2 ... aN
b1 b2 ... bN
Q
x1 y1 z1
x2 y2 z2
...
xQ yQ zQ
Output
Every time a statement of x=3 or x=4 is given by input, the found value is output on one line.
Example
Input
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
Output
7
2
2
8
1
样例
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
7
2
2
8
1
</p>