#abc294c. C - Merge Sequences

C - Merge Sequences

Score : 300300 points

问题描述

你已知两个严格递增的序列,长度分别为 NNMM: 序列 A=(A1,A2,,AN)A=(A _ 1,A _ 2,\ldots,A _ N) 以及序列 B=(B1,B2,,BM)B=(B _ 1,B _ 2,\ldots,B _ M)。这里,对于任意的 iijj(满足 1iN,1jM1\leq i\leq N,1\leq j\leq M),有 AiBjA _ i\neq B _ j

C=(C1,C2,,CN+M)C=(C _ 1,C _ 2,\ldots,C _ {N+M}) 是一个通过以下步骤得到的长度为 N+MN+M 的严格递增序列。

  • CC 定义为 AABB 的串联。形式上,令 Ci=AiC _ i=A _ i 对于 i=1,2,,Ni=1,2,\ldots,N,并且令 Ci=BiNC _ i=B _ {i-N} 对于 i=N+1,N+2,,N+Mi=N+1,N+2,\ldots,N+M
  • CC 按升序排序。

对于 A1,A2,,ANA _ 1,A _ 2,\ldots,A _ NB1,B2,,BMB _ 1,B _ 2,\ldots,B _ M 中的每一个元素,找出其在 CC 中的位置。更具体地讲,对于每个 i=1,2,,Ni=1,2,\ldots,N,找到满足 Ck=AiC _ k=A _ ikk 值;对于每个 j=1,2,,Mj=1,2,\ldots,M,找到满足 Ck=BjC _ k=B _ jkk 值。

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

Problem Statement

You are given strictly increasing sequences of length NN and MM: A=(A1,A2,,AN)A=(A _ 1,A _ 2,\ldots,A _ N) and B=(B1,B2,,BM)B=(B _ 1,B _ 2,\ldots,B _ M). Here, AiBjA _ i\neq B _ j for every ii and jj (1iN,1jM)(1\leq i\leq N,1\leq j\leq M).

Let C=(C1,C2,,CN+M)C=(C _ 1,C _ 2,\ldots,C _ {N+M}) be a strictly increasing sequence of length N+MN+M that results from the following procedure.

  • Let CC be the concatenation of AA and BB. Formally, let Ci=AiC _ i=A _ i for i=1,2,,Ni=1,2,\ldots,N, and Ci=BiNC _ i=B _ {i-N} for i=N+1,N+2,,N+Mi=N+1,N+2,\ldots,N+M.
  • Sort CC in ascending order.

For each of A1,A2,,AN,B1,B2,,BMA _ 1,A _ 2,\ldots,A _ N, B _ 1,B _ 2,\ldots,B _ M, find its position in CC. More formally, for each i=1,2,,Ni=1,2,\ldots,N, find kk such that Ck=AiC _ k=A _ i, and for each j=1,2,,Mj=1,2,\ldots,M, find kk such that Ck=BjC _ k=B _ j.

Constraints

  • 1N,M1051\leq N,M\leq 10^5
  • 1A1<A2<<AN1091\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq 10^9
  • 1B1<B2<<BM1091\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\leq 10^9
  • AiBjA _ i\neq B _ j for every ii and jj (1iN,1jM)(1\leq i\leq N,1\leq j\leq M).
  • All values in the input are integers.

Input

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

NN MM

A1A _ 1 A2A _ 2 \ldots ANA _ N

B1B _ 1 B2B _ 2 \ldots BMB _ M

Output

Print the answer in two lines.
The first line should contain the positions of A1,A2,,ANA _ 1,A _ 2,\ldots,A _ N in CC, with spaces in between.
The second line should contain the positions of B1,B2,,BMB _ 1,B _ 2,\ldots,B _ M in CC, with spaces in between.

Sample Input 1

4 3
3 14 15 92
6 53 58

Sample Output 1

1 3 4 7
2 5 6

CC will be (3,6,14,15,53,58,92)(3,6,14,15,53,58,92). Here, the 11-st, 33-rd, 44-th, 77-th elements are from A=(3,14,15,92)A=(3,14,15,92), and the 22-nd, 55-th, 66-th elements are from B=(6,53,58)B=(6,53,58).

Sample Input 2

4 4
1 2 3 4
100 200 300 400

Sample Output 2

1 2 3 4
5 6 7 8

Sample Input 3

8 12
3 4 10 15 17 18 22 30
5 7 11 13 14 16 19 21 23 24 27 28

Sample Output 3

1 2 5 9 11 12 15 20
3 4 6 7 8 10 13 14 16 17 18 19

update @ 2024/3/10 12:14:01