Orig Description
A: Information Search
Problem
A posting list is a list that associates search words with the corresponding document IDs where the words appear. For example,
Hokkaido: 1, 2, 4, 9
Tourism: 1, 3, 4, 7
and so on.
From the above posting list, when conducting an "and search", documents with IDs 1 and 4 are hit, and when conducting an "or search", documents with IDs 1, 2, 3, 4, 7, and 9 are hit.
Here, an "and search" refers to the process of listing the elements that are included in both lists, and an "or search" refers to the process of listing the elements that are included in at least one of the lists.
Given the posting list, output the results of both "and search" and "or search".
Input Format
n m
a_1 a_2 $\ldots$ a_n
b_1 b_2 $\ldots$ b_m
All input is an integer.
The first line contains the lengths of the two posting lists to be searched, n and m, separated by a space.
The second and third lines contain the IDs included in each posting list, separated by spaces.
Constraints
1 \leq n, m \leq 2\times10^5
a_i < a_j (i < j)
b_i < b_j (i < j)
1 \leq a_i, b_i \leq 10^9
Output Format
Let A be the number of hits in the "and search" and B be the number of hits in the "or search".
Output a single line containing A B.
Output the IDs that were hit in ascending order for the "and search" on the next A lines.
Output the IDs that were hit in ascending order for the "or search" on the next B lines.
Sample Input 1
4 4
1 2 4 9
1 3 4 7
Sample Output 1
2 6
1
4
1
2
3
4
7
9
Sample Input 2
4 4
1 3 5 7
2 4 6 8
Sample Output 2
0 8
1
2
3
4
5
6
7
8
Sample Input 3
3 5
1 2 3
1 2 3 4 5
Sample Output 3
3 5
1
2
3
1
2
3
4
5
Extracted Specification
An integer n (1 ≤ n ≤ 2×10^5), representing some quantity or size.
An integer m (1 ≤ m ≤ 2×10^5), representing some quantity or size.
A list of integers of size n, where each integer is between 1 and 10^9, in strictly increasing order.
A list of integers of size m, where each integer is between 1 and 10^9, in strictly increasing order.
### Example Input:
```
4 4
1 2 4 9
1 3 4 7
```
### Function Signature:
Write a function f(n, m, A, B) that takes in the input.
def f(n: int, m: int, A: List[int], B: List[int]):
'''
n: an integer
m: an integer
A: a list of integers
B: a list of integers
'''
Test Case Generator
Certainly! Below is a Python function that generates test cases for the given problem statement "Information Search". This function will create random lengths for the posting lists and populate them with unique, sorted document IDs as required by the problem's constraints.
```python
import random
def tcgen():
# Random lengths for the posting lists within the given constraints
n = random.randint(1, 2 * 10**5)
m = random.randint(1, 2 * 10**5)
# Generate unique and sorted document IDs for list A
a = sorted(random.sample(range(1, 10**9), n))
# Generate unique and sorted document IDs for list B
b = sorted(random.sample(range(1, 10**9), m))
return n, m, a, b
# Example of generating a test case and printing it
n, m, a, b = tcgen()
print(n, m)
print(' '.join(map(str, a)))
print(' '.join(map(str, b)))
```
### Explanation:
1. **Lengths of Posting Lists (n and m)**: We generate random integers between 1 and 200,000 for `n` and `m`.
2. **Document IDs**: Using `random.sample`, we create a unique set of `n` and `m` integers within the range from 1 to \(10^9\) for lists `a` and `b`. This ensures that:
- Each list contains unique IDs.
- The IDs are sorted in ascending order.
This will generate test cases that conform to the constraints and structure outlined in the problem statement. You can run the `tcgen` function to generate different test cases each time.
Extract Arguments
def extract_arguments(fh):
n, m = map(int, fh.readline().strip().split())
a = list(map(int, fh.readline().strip().split()))
b = list(map(int, fh.readline().strip().split()))
return n, m, a, b