CF1847F.The Boss's Identity
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
While tracking Diavolo's origins, Giorno receives a secret code from Polnareff. The code can be represented as an infinite sequence of positive integers: $a_1, a_2, \dots $ . Giorno immediately sees the pattern behind the code. The first n numbers a1,a2,…,an are given. For i>n the value of ai is (ai−n ∣ ai−n+1) , where ∣ denotes the bitwise OR operator.
Pieces of information about Diavolo are hidden in q questions. Each question has a positive integer v associated with it and its answer is the smallest index i such that ai>v . If no such i exists, the answer is −1 . Help Giorno in answering the questions!
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤10000 ). The description of the test cases follows.
The first line of each test case contains two integers n and q ( 2≤n≤2⋅105 , 1≤q≤2⋅105 ).
The second line of each test case contains n integers a1,a2,…,an ( 0≤ai≤109 ) — the parts of the code which define the pattern.
The i -th line of the next q lines contain a single integer vi ( 0≤vi≤109 ) — the question Giorno asks you.
The sum of n and q over all test cases does not exceed 2⋅105 .
输出格式
Print q numbers. The i -th number is the answer to the i -th question asked by Giorno.
输入输出样例
输入#1
3 2 3 2 1 1 2 3 4 5 0 2 1 3 0 1 2 3 4 5 5 1 2 3 4 5 7 2 6 0 4
输出#1
1 3 -1 2 2 4 -1 -1 -1 3 8 1 5
说明/提示
In the first test case, a=[2,1,3,3,…] .
- For the first question, a1=2 is the element with the smallest index greater than 1 .
- For the second question, a3=3 is the element with the smallest index greater than 2 .
- For the third question, there is no index i such that ai>3 .