CF1847F.The Boss's Identity

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

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 nn numbers a1,a2,…,ana_1, a_2, \dots, a_n are given. For i>ni \gt n the value of aia_i is (ai−n ∣ ai−n+1)(a_{i-n}\ |\ a_{i-n+1}), where ∣| denotes the bitwise OR operator.

Pieces of information about Diavolo are hidden in qq questions. Each question has a positive integer vv associated with it and its answer is the smallest index ii such that ai>va_i \gt v. If no such ii exists, the answer is −1-1. Help Giorno in answering the questions!

在追踪迪亚波罗的起源时,乔鲁诺从波鲁纳雷夫那里收到了一段秘密代码。该代码可表示为一个无限的正整数序列:$a_1, a_2, \dots $。乔鲁诺立刻看出了这段代码背后的规律。前 nn 个数 a1,a2,…,ana_1, a_2, \dots, a_n 已给出;对于 i>ni > n,有 ai=(ai−n ∣ ai−n+1)a_i = (a_{i-n}\ |\ a_{i-n+1}),其中 ∣| 表示按位或运算符。

有关迪亚波罗的信息隐藏在 qq 个问题中。每个问题关联一个正整数 vv,其答案为满足 ai>va_i > v 的最小下标 ii;若不存在这样的 ii,则答案为 −1-1。请帮助乔鲁诺回答这些问题!

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10 0001 \le t \le 10\,000). The description of the test cases follows.

The first line of each test case contains two integers nn and qq (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5 , 1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai≤1090 \leq a_i \leq 10^9) — the parts of the code which define the pattern.

The ii-th line of the next qq lines contain a single integer viv_i (0≤vi≤1090 \leq v_i \leq 10^9) — the question Giorno asks you.

The sum of nn and qq over all test cases does not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含两个整数 nn 和 qq(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5,1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤1090 \leq a_i \leq 10^9)——这些是定义模式的代码片段。

接下来 qq 行中的第 ii 行包含一个整数 viv_i(0≤vi≤1090 \leq v_i \leq 10^9)——这是乔鲁诺向你提出的第 ii 个问题。

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

输出格式

Print qq numbers. The ii-th number is the answer to the ii-th question asked by Giorno.

输出 qq 个数。其中第 ii 个数是乔鲁诺提出的第 ii 个问题的答案。

输入输出样例

  • 输入#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,…]a = [2,1,3,3,\ldots].

  • For the first question, a1=2a_1=2 is the element with the smallest index greater than 11.
  • For the second question, a3=3a_3=3 is the element with the smallest index greater than 22.
  • For the third question, there is no index ii such that ai>3a_i \gt 3.

在第一个测试用例中,a=[2,1,3,3,…]a = [2,1,3,3,\ldots]。

  • 对于第一个询问,a1=2a_1=2 是下标大于 11 的元素中下标最小的元素。
  • 对于第二个询问,a3=3a_3=3 是下标大于 22 的元素中下标最小的元素。
  • 对于第三个询问,不存在下标 ii 使得 ai>3a_i \gt 3。

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

首页