#P1936D. Bitwise Paradox

    ID: 10387 Type: RemoteJudge 5000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>binary searchbitmasksdata structuresgreedytwo pointers*3100

Bitwise Paradox

Description

You are given two arrays aa and bb of size nn along with a fixed integer vv.

An interval [l,r][l, r] is called a good interval if (blbl+1br)v(b_l \mid b_{l+1} \mid \ldots \mid b_r) \ge v, where | denotes the bitwise OR operation. The beauty of a good interval is defined as max(al,al+1,,ar)\max(a_l, a_{l+1}, \ldots, a_r).

You are given qq queries of two types:

  • "1 i x": assign bi:=xb_i := x;
  • "2 l r": find the minimum beauty among all good intervals [l0,r0][l_0,r_0] satisfying ll0r0rl \le l_0 \le r_0 \le r. If there is no suitable good interval, output 1-1 instead.

Please process all queries.

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains two integers nn and vv (1n21051 \le n \le 2 \cdot 10^5, 1v1091 \le v \le 10^9).

The second line of each testcase contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9).

The third line of each testcase contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n (1bi1091 \le b_i \le 10^9).

The fourth line of each testcase contains one integer qq (1q21051 \le q \le 2 \cdot 10^5).

The ii-th of the following qq lines contains the description of queries. Each line is of one of two types:

  • "1 i x" (1in1 \le i \le n, 1x109)1 \le x \le 10^9);
  • "2 l r" (1lrn1 \le l \le r \le n).

It is guaranteed that both the sum of nn and the sum of qq over all test cases do not exceed 21052 \cdot 10^5.

For each test case, output the answers for all queries of the second type.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains two integers nn and vv (1n21051 \le n \le 2 \cdot 10^5, 1v1091 \le v \le 10^9).

The second line of each testcase contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9).

The third line of each testcase contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n (1bi1091 \le b_i \le 10^9).

The fourth line of each testcase contains one integer qq (1q21051 \le q \le 2 \cdot 10^5).

The ii-th of the following qq lines contains the description of queries. Each line is of one of two types:

  • "1 i x" (1in1 \le i \le n, 1x109)1 \le x \le 10^9);
  • "2 l r" (1lrn1 \le l \le r \le n).

It is guaranteed that both the sum of nn and the sum of qq over all test cases do not exceed 21052 \cdot 10^5.

Output

For each test case, output the answers for all queries of the second type.

Sample Input 1

3
3 7
2 1 3
2 2 3
4
2 1 3
1 2 5
2 2 3
2 1 3
4 5
5 1 2 4
4 2 3 3
6
2 1 4
1 3 15
2 3 4
2 2 4
1 2 13
2 1 4
1 5
6
4
1
2 1 1

Sample Output 1

-1 3 2 
5 2 2 1 
-1

Note

In the first test case, a=[2,1,3]a = [2, 1, 3], b=[2,2,3]b = [2, 2, 3], and v=7v = 7.

The first query is of the second type and has l=1l = 1 and r=3r = 3. The largest interval available is [1,3][1, 3], and its bitwise OR is b1b2b3=3b_1 \mid b_2 \mid b_3 = 3 which is less than vv. Thus, no good interval exists.

The second query asks to change b2b_2 to 55, so bb becomes [2,5,3][2, 5, 3].

The third query is of the second type and has l=2l = 2 and r=3r = 3. There are three possible intervals: [2,2][2, 2], [3,3][3, 3], and [2,3][2, 3]. However, b2=5<vb_2 = 5 < v, b3=3<vb_3 = 3 < v. So only the last interval is good: it has b2b3=7b_2 \mid b_3 = 7. The answer is thus max(a2,a3)=3\max(a_2, a_3) = 3.

The fourth query is of the second type and has l=1l = 1 and r=3r = 3. There are three good intervals: [1,2][1, 2], [2,3][2, 3], and [1,3][1, 3]. Their beauty is 22, 33, 33 correspondingly. The answer is thus 22.

In the second test case, a=[5,1,2,4]a = [5, 1, 2, 4], b=[4,2,3,3]b = [4, 2, 3, 3], and v=5v = 5.

The first query has l=1l = 1 and r=4r = 4. The only good intervals are: [1,2][1, 2], [1,3][1, 3], [1,4][1, 4]. Their beauty is 55, 55, 55 correspondingly. The answer is thus 55.