Logo
(追記) (追記ここまで)

30299번 - Wrong Queue 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB98171214.815%

문제

A 'Queue' is a linear data structure that can either

  1. Insert an element at the back (push)
  2. Delete an element at the front (pop).

However we misimplemented the pop function; for each pop query, we simultaneously delete $N$ certain elements from different indices, instead of deleting only one element at the front.

Specifically, there are $N$ distinct locations where our pop function deletes its elements, noted by $A_1,ドル $A_2,ドル ..., $A_N$. The queue is indexed from 1ドル$ starting at the front. After deletion, the indices are renamed with the same rule described above.

But we are curious what the misimplemented queue will look like after $D$ pop operations.

In order to conduct an experiment, we first pushed infinitely many integers in the queue starting from 1. So the initial queue will look like "1 2 3 4 5 6 7 8...".

Then without further push operations, we will pop the queue $D$ times.

For example, assume the current queue was "1 2 3 4 5 6 7 8...". If we delete the 2nd and 5th element, the queue will change to "1 3 4 6 7 8 9 10...". If we do it again, it will be "1 4 6 8 9 10 11 12..." and so on.

We want to process $Q$ queries consisting of a single integer $x$. For each query, we need to calculate the number written in the $x$th index of the queue after $D$ pop operations.

입력

The first line contains $N$.

The second line contains $N$ space-seperated integers $A_1,ドル $A_2,ドル ..., $A_N$ denoting the indexes we delete for each pop operation.

The third line contains two space-seperated integers $Q,ドル $D$ denoting the number of queries and the number of pop operations respectively.

The following $Q$ lines contain an integer $x$ denoting each query.

출력

Output $Q$ lines, where the $i$th line contains a single integer denoting the answer of the $i$th query.

제한

  • 1ドル\leq N\leq 500,000円$
  • 1ドル\leq A_i\leq 10^{12}$
  • All $A_i$s are distinct.
  • 1ドル\leq Q\leq 500,000円$
  • 1ドル\leq D\leq 10^{12}$
  • 1ドル\leq x\leq 10^{12}$ for all queries

예제 입력 1

2
2 5
8 2
1
2
3
4
5
6
7
8

예제 출력 1

1
4
6
8
9
10
11
12

예제 입력 2

3
7 1 32
8 5
2
8
7
17
26
19
3
1

예제 출력 2

8
18
17
27
39
29
10
6

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2023 KAIST 13th ICPC Mock Competition H번

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 2: K-ontest H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /