CF1936D.Bitwise Paradox

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 (bl∣bl+1∣…∣br)≥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 l≤l0≤r0≤rl \le l_0 \le r_0 \le r. If there is no suitable good interval, output −1-1 instead.

Please process all queries.

给你两个长度为 nn 的数组 aa 和 bb,以及一个固定整数 vv。

若区间 [l,r][l, r] 满足 (bl∣bl+1∣…∣br)≥v(b_l \mid b_{l+1} \mid \ldots \mid b_r) \ge v,则称其为好区间,其中 ∣| 表示按位或运算。一个好区间的美丽值定义为 max⁡(al,al+1,…,ar)\max(a_l, a_{l+1}, \ldots, a_r)。

你将收到 qq 个查询,分为两类:

  • “1 i x”:将 bib_i 赋值为 xx;
  • “2 l r”:在所有满足 l≤l0≤r0≤rl \le l_0 \le r_0 \le r 的好区间 [l0,r0][l_0,r_0] 中,找出最小的美丽值;若不存在这样的好区间,则输出 −1-1。

请处理全部查询。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \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 (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤v≤1091 \le v \le 10^9).

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

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

The fourth line of each testcase contains one integer qq (1≤q≤2⋅1051 \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" (1≤i≤n1 \le i \le n, 1≤x≤109)1 \le x \le 10^9);
  • "2 l r" (1≤l≤r≤n1 \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 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1051 \le t \le 10^5)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 vv(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤v≤1091 \le v \le 10^9)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

每个测试用例的第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \le b_i \le 10^9)。

每个测试用例的第四行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)。

接下来的 qq 行中,第 ii 行描述一个查询,每行属于以下两种类型之一:

  • “1 i x”(1≤i≤n1 \le i \le n,1≤x≤1091 \le x \le 10^9);
  • “2 l r”(1≤l≤r≤n1 \le l \le r \le n)。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

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

对于每个测试用例,输出所有第二类查询的答案。

输入输出样例

  • 输入#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

    输出#1

    -1 3 2 
    5 2 2 1 
    -1

说明/提示

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 b1∣b2∣b3=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 \lt v, b3=3<vb_3 = 3 \lt v. So only the last interval is good: it has b2∣b3=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.

在第一个测试用例中,a=[2,1,3]a = [2, 1, 3],b=[2,2,3]b = [2, 2, 3],且 v=7v = 7。

第一个查询为第二类查询,参数为 l=1l = 1 和 r=3r = 3。当前可选的最大区间为 [1,3][1, 3],其按位或值为 b1∣b2∣b3=3b_1 \mid b_2 \mid b_3 = 3,小于 vv。因此,不存在好区间。

第二个查询要求将 b2b_2 修改为 55,于是 bb 变为 [2,5,3][2, 5, 3]。

第三个查询为第二类查询,参数为 l=2l = 2 和 r=3r = 3。共有三个可能的区间:[2,2][2, 2]、[3,3][3, 3] 和 [2,3][2, 3]。但 b2=5<vb_2 = 5 \lt v,b3=3<vb_3 = 3 \lt v,因此仅最后一个区间是好区间:其按位或值为 b2∣b3=7b_2 \mid b_3 = 7。答案即为 max⁡(a2,a3)=3\max(a_2, a_3) = 3。

第四个查询为第二类查询,参数为 l=1l = 1 和 r=3r = 3。共有三个好区间:[1,2][1, 2]、[2,3][2, 3] 和 [1,3][1, 3]。它们的美丽值分别为 22、33、33。因此答案为 22。

在第二个测试用例中,a=[5,1,2,4]a = [5, 1, 2, 4],b=[4,2,3,3]b = [4, 2, 3, 3],且 v=5v = 5。

第一个查询参数为 l=1l = 1 和 r=4r = 4。唯一的好区间为:[1,2][1, 2]、[1,3][1, 3] 和 [1,4][1, 4]。它们的美丽值均为 55。因此答案为 55。

输入解题思路,AI测评打分。不知道怎么写?

首页