| AGM 2021, Qualification Round |
|---|
| Finished |
Nix has stumbled upon the legendary quest of Ohara. There are two arrays of numbers, of length $$$N$$$ and $$$M$$$ respectively. For each number from the first array, Ohara wants to know what is the lowest and highest value of an Ohara match. An Ohara match is defined as follows:
Nix finds this quest rather challenging, so she asks for your help in finding the answer.
The first line of the input contains the numbers $$$N$$$ and $$$M$$$, the length of the first and second array of numbers. The second line contains $$$N$$$ integers $$$a_1, a_2,\dots\ a_N$$$ ($$$1 \leq N \leq 10^5,\ 1 \leq a_i \lt 2^{21}$$$), the numbers from the first array. The third line contains $$$M$$$ integers $$$b_1, b_2,\dots\ b_M$$$ ($$$1 \leq b_i \leq 10^9)$$$, the numbers from the second array. It is also guaranteed that the length of the Ohara string is at most $$$10^5$$$.
The output will contain $$$N$$$ lines. The $$$i^{th}$$$ line will contain a pair of integers: the smallest and highest value of an Ohara match for the $$$i^{th}$$$ number in the first array. If there is no Ohara match for that number output -1 -1.
1 2 5 4 1
1 2
1 2 13 3 6
4 4
In the first example we get the lowest value matching by transforming 101 into 100and matching on firstbit of 4 from the second array, thus 20= 1. The highest value matching is obtained by transforming101 into001 and matching on the second bit of 4 from the second array, thus 21= 2.
| Name |
|---|


