#C4189. Count Good Arrangements
Count Good Arrangements
Count Good Arrangements
You are given a collection of books, each identified by a genre number. Your task is to determine for each queried genre whether there exists at least one "good arrangement" of the books when they are sorted in ascending order. In a good arrangement, the books are first sorted in ascending order and then grouped into exactly k subsections. However, note that there is only one possible way to arrange the sorted books into subsections, hence if a queried genre exists in the list of book genres, the answer is 1; otherwise, it is 0.
Mathematically, let \(G\) be the sorted array of the genres, then for each preferred genre \(g\), the result is defined as:
[ \text{result}(g) = \begin{cases} 1, & \text{if} ; g \in G \ 0, & \text{otherwise} \end{cases} ]
You need to implement a program that reads the input from standard input and outputs the answer to standard output.
inputFormat
The input is given in the following format from standard input.
n k genres (n space separated integers) l preferred_genres (l space separated integers)
where:
- n is the number of books.
- k is the number of subsections (not used in the calculation as the arrangement is uniquely determined).
- genres is a list of n integers representing the genres of the books.
- l is the number of preferred genres queried.
- preferred_genres is a list of l integers representing the genres to check.
outputFormat
The output should consist of a single line containing l integers separated by spaces, where each integer corresponds to the result for the respective preferred genre (1 if present in the sorted list of genres; otherwise, 0).
## sample5 2
3 1 2 5 4
3
2 4 5
1 1 1