#K34567. Wildlife Recording Analysis
Wildlife Recording Analysis
Wildlife Recording Analysis
A wildlife observation team has set up multiple cameras in a forest to track animal movements. Each camera records a sequence of animal identifications as a string. Your task is to determine for each query whether there exists any recording in which a given base sequence is immediately followed by a target sequence. This ability to spot specific patterns in the recordings can help researchers identify behavioral patterns of wildlife.
Formally, you are given an integer \(n\) representing the number of recordings and an integer \(q\) representing the number of queries. Each recording is a string, and each query consists of two strings: a base sequence and a target sequence. For each query, if the concatenation \(\text{base} + \text{target}\) appears as a contiguous substring in any recording, print YES
; otherwise, print NO
.
Note: The concatenation must occur exactly as the base sequence immediately followed by the target sequence.
inputFormat
The input is read from stdin and has the following format:
n q recording_1 recording_2 ... (n recordings) base_1 target_1 base_2 target_2 ... (q queries)
Where:
- n is the number of camera recordings.
- q is the number of queries.
- Each recording is provided on a separate line.
- Each query consists of two space-separated strings representing the base sequence and the target sequence.
outputFormat
For each query, print YES
if there is at least one recording where the base sequence is immediately followed by the target sequence. Otherwise, print NO
. Each answer must be printed on a new line to stdout.
2 2
abcde
fghij
abc de
fgh ij
YES
YES
</p>