トヨタシステムズプログラミングコンテスト2025(AtCoder Beginner Contest 431)
G
One Time Swap 2
AtCoder
⌀ 2490
原题
翻译中…

Problem Statement

翻译中…

You are given an integer sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$.

翻译中…

For a pair of integers $(l, r) \ (1\leq l\lt r\leq N)$, let $f(l,r)$ be the integer sequence obtained by swapping the $l$-th element and the $r$-th element of $A$.

翻译中…

Generate a sequence of integer sequences $B=(B_1,B_2,\ldots,B_{\frac{N(N-1)}{2}})$ of length $\frac{N(N-1)}{2}$ by the following procedure:

翻译中…
  • Prepare an empty sequence $B=()$.
  • For each pair of integers $(l, r)\ (1\leq l\lt r\leq N)$, add $f(l,r)$ to $B$.
  • Sort $B$ in lexicographical order of sequences.
翻译中…

You are given $Q$ queries; process them in order. The $i$-th query is as follows:

翻译中…
  • Given an integer $k$, find one pair of integers $(l, r) \ (1\leq l\lt r\leq N)$ such that $B_k=f(l,r)$ and output it.
翻译中…

What is lexicographical order of sequences? A sequence $S = (S_1,S_2,\ldots,S_{|S|})$ is lexicographically smaller than a sequence $T = (T_1,T_2,\ldots,T_{|T|})$ if and only if one of the following two conditions holds. Here, $|S|$ and $|T|$ represent the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $(S_1,S_2,\ldots,S_{|S|}) = (T_1,T_2,\ldots,T_{|S|})$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following hold: $(S_1,S_2,\ldots,S_{i-1}) = (T_1,T_2,\ldots,T_{i-1})$ $S_i$ is smaller than $T_i$ (as a number).

翻译中…

Constraints

翻译中…
  • $2\leq N\leq 2\times 10^5$
  • $1\leq Q\leq 2\times 10^5$
  • $1\leq A_i\leq N$
  • $1\leq k\leq \frac{N(N-1)}{2}$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N Q
A_1 A_2 \ldots A_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

翻译中…

Each query is given in the following format:

翻译中…

k

翻译中…

Output

翻译中…

Output $Q$ lines. The $i$-th line should contain the answer to the $i$-th query in the following format:

翻译中…

l r

翻译中…

If there are multiple solutions, any of them will be considered correct.

翻译中…

样例

Input #1
4 3
1 2 1 2
1
3
5
Output #1
2 3
2 4
1 2
$f(1, 2) = (2, 1, 1, 2), f(1, 3) = (1, 2, 1, 2), f(1, 4) = (2, 2, 1, 1), f(2, 3) = (1, 1, 2, 2), f(2, 4) = (1, 2, 1, 2), f(3, 4) = (1, 2, 2, 1)$. The sequence $B$ obtained by sorting these six sequences in lexicographical order is $B=((1, 1, 2, 2), (1, 2, 1, 2), (1, 2, 1, 2), (1, 2, 2, 1), (2, 1, 1, 2), (2, 2, 1, 1))$. - For the $1$-st query, the only $(l,r)$ such that $B_1=(1,1,2,2)=f(l,r)$ is $(l,r)=(2,3)$. - For the $2$-nd query, $(l,r)$ such that $B_3=(1,2,1,2)=f(l,r)$ are $(l,r)=(1,3),(2,4)$. In this case, either one will be considered correct. - For the $3$-rd query, the only $(l,r)$ such that $B_5=(2,1,1,2)=f(l,r)$ is $(l,r)=(1,2)$.
Input #2
10 10
1 1 2 7 6 3 5 7 3 3
21
36
9
17
13
24
7
45
33
1
Output #2
6 8
2 4
5 7
9 10
8 9
3 9
5 9
1 8
2 10
4 10
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。