Score : 300 points
问题描述
你已知两个严格递增的序列,长度分别为 N 和 M: 序列 A=(A1,A2,…,AN) 以及序列 B=(B1,B2,…,BM)。这里,对于任意的 i 和 j(满足 1≤i≤N,1≤j≤M),有 Ai=Bj。
令 C=(C1,C2,…,CN+M) 是一个通过以下步骤得到的长度为 N+M 的严格递增序列。
- 将 C 定义为 A 和 B 的串联。形式上,令 Ci=Ai 对于 i=1,2,…,N,并且令 Ci=Bi−N 对于 i=N+1,N+2,…,N+M。
- 将 C 按升序排序。
对于 A1,A2,…,AN 和 B1,B2,…,BM 中的每一个元素,找出其在 C 中的位置。更具体地讲,对于每个 i=1,2,…,N,找到满足 Ck=Ai 的 k 值;对于每个 j=1,2,…,M,找到满足 Ck=Bj 的 k 值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given strictly increasing sequences of length N and M: A=(A1,A2,…,AN) and B=(B1,B2,…,BM). Here, Ai=Bj for every i and j (1≤i≤N,1≤j≤M).
Let C=(C1,C2,…,CN+M) be a strictly increasing sequence of length N+M that results from the following procedure.
- Let C be the concatenation of A and B. Formally, let Ci=Ai for i=1,2,…,N, and Ci=Bi−N for i=N+1,N+2,…,N+M.
- Sort C in ascending order.
For each of A1,A2,…,AN,B1,B2,…,BM, find its position in C. More formally, for each i=1,2,…,N, find k such that Ck=Ai, and for each j=1,2,…,M, find k such that Ck=Bj.
Constraints
- 1≤N,M≤105
- 1≤A1<A2<⋯<AN≤109
- 1≤B1<B2<⋯<BM≤109
- Ai=Bj for every i and j (1≤i≤N,1≤j≤M).
- All values in the input are integers.
The input is given from Standard Input in the following format:
N M
A1 A2 … AN
B1 B2 … BM
Output
Print the answer in two lines.
The first line should contain the positions of A1,A2,…,AN in C, with spaces in between.
The second line should contain the positions of B1,B2,…,BM in C, with spaces in between.
4 3
3 14 15 92
6 53 58
Sample Output 1
1 3 4 7
2 5 6
C will be (3,6,14,15,53,58,92). Here, the 1-st, 3-rd, 4-th, 7-th elements are from A=(3,14,15,92), and the 2-nd, 5-th, 6-th elements are from B=(6,53,58).
4 4
1 2 3 4
100 200 300 400
Sample Output 2
1 2 3 4
5 6 7 8
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