CF1936D.Bitwise Paradox
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two arrays a and b of size n along with a fixed integer v .
An interval [l,r] is called a good interval if (bl∣bl+1∣…∣br)≥v , where ∣ denotes the bitwise OR operation. The beauty of a good interval is defined as max(al,al+1,…,ar) .
You are given q queries of two types:
- "1 i x": assign bi:=x ;
- "2 l r": find the minimum beauty among all good intervals [l0,r0] satisfying l≤l0≤r0≤r . If there is no suitable good interval, output −1 instead.
Please process all queries.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤105 ). The description of the test cases follows.
The first line of each test case contains two integers n and v ( 1≤n≤2⋅105 , 1≤v≤109 ).
The second line of each testcase contains n integers a1,a2,…,an ( 1≤ai≤109 ).
The third line of each testcase contains n integers b1,b2,…,bn ( 1≤bi≤109 ).
The fourth line of each testcase contains one integer q ( 1≤q≤2⋅105 ).
The i -th of the following q lines contains the description of queries. Each line is of one of two types:
- "1 i x" ( 1≤i≤n , 1≤x≤109) ;
- "2 l r" ( 1≤l≤r≤n ).
It is guaranteed that both the sum of n and the sum of q over all test cases do not exceed 2⋅105 .
输出格式
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] , b=[2,2,3] , and v=7 .
The first query is of the second type and has l=1 and r=3 . The largest interval available is [1,3] , and its bitwise OR is b1∣b2∣b3=3 which is less than v . Thus, no good interval exists.
The second query asks to change b2 to 5 , so b becomes [2,5,3] .
The third query is of the second type and has l=2 and r=3 . There are three possible intervals: [2,2] , [3,3] , and [2,3] . However, b2=5<v , b3=3<v . So only the last interval is good: it has b2∣b3=7 . The answer is thus max(a2,a3)=3 .
The fourth query is of the second type and has l=1 and r=3 . There are three good intervals: [1,2] , [2,3] , and [1,3] . Their beauty is 2 , 3 , 3 correspondingly. The answer is thus 2 .
In the second test case, a=[5,1,2,4] , b=[4,2,3,3] , and v=5 .
The first query has l=1 and r=4 . The only good intervals are: [1,2] , [1,3] , [1,4] . Their beauty is 5 , 5 , 5 correspondingly. The answer is thus 5 .