#abc205d. D - Kth Excluded

D - Kth Excluded

Score : 400400 points

问题描述

你将获得一个包含 NN 个正整数的序列:A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N),以及 QQ 个查询请求。

在第 ii 个查询中 (1iQ)(1 \leq i \leq Q),给定一个正整数 KiK_i,找出与所有 A1,A2,,ANA_1, A_2, \dots, A_N 不同的正整数中的第 KiK_i 小的整数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of NN positive integers: A=(A1,A2,,AN)A = (A_1, A_2, \dots, A_N), and QQ queries.

In the ii-th query (1iQ)(1 \leq i \leq Q), given a positive integer KiK_i, find the KiK_i-th smallest integer among the positive integers that differ from all of A1,A2,,ANA_1, A_2, \dots, A_N.

Constraints

  • 1N,Q1051 \leq N, Q \leq 10^5
  • 1A1<A2<<AN10181 \leq A_1 < A_2 < \dots < A_N \leq 10^{18}
  • 1Ki10181 \leq K_i \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ

A1A_1 A2A_2 \ldots ANA_N

K1K_1

K2K_2

\vdots

KQK_Q

Output

Print QQ lines. The ii-th line should contain the response to the ii-th query.

Sample Input 1

4 3
3 5 6 7
2
5
3

Sample Output 1

2
9
4

The positive integers that differ from all of A1,A2,,ANA_1, A_2, \dots, A_N are 1,2,4,8,9,10,11,1, 2, 4, 8, 9, 10, 11, \dots in ascending order. The second, fifth, and third smallest of them are 22, 99, and 44, respectively.

Sample Input 2

5 2
1 2 3 4 5
1
10

Sample Output 2

6
15

update @ 2024/3/10 09:18:30