|
| 1 | +# python3 |
| 2 | +import sys |
| 3 | + |
| 4 | + |
| 5 | +def PreprocessBWT(bwt): |
| 6 | + """ |
| 7 | + Preprocess the Burrows-Wheeler Transform bwt of some text |
| 8 | + and compute as a result: |
| 9 | + * starts - for each character C in bwt, starts[C] is the first position |
| 10 | + of this character in the sorted array of |
| 11 | + all characters of the text. |
| 12 | + * occ_count_before - for each character C in bwt and each position P in bwt, |
| 13 | + occ_count_before[C][P] is the number of occurrences of character C in bwt |
| 14 | + from position 0 to position P inclusive. |
| 15 | + """ |
| 16 | + # Implement this function yourself |
| 17 | + pass |
| 18 | + |
| 19 | + |
| 20 | +def CountOccurrences(pattern, bwt, starts, occ_counts_before): |
| 21 | + """ |
| 22 | + Compute the number of occurrences of string pattern in the text |
| 23 | + given only Burrows-Wheeler Transform bwt of the text and additional |
| 24 | + information we get from the preprocessing stage - starts and occ_counts_before. |
| 25 | + """ |
| 26 | + # Implement this function yourself |
| 27 | + return 0 |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +if __name__ == '__main__': |
| 32 | + bwt = sys.stdin.readline().strip() |
| 33 | + pattern_count = int(sys.stdin.readline().strip()) |
| 34 | + patterns = sys.stdin.readline().strip().split() |
| 35 | + # Preprocess the BWT once to get starts and occ_count_before. |
| 36 | + # For each pattern, we will then use these precomputed values and |
| 37 | + # spend only O(|pattern|) to find all occurrences of the pattern |
| 38 | + # in the text instead of O(|pattern| + |text|). |
| 39 | + starts, occ_counts_before = PreprocessBWT(bwt) |
| 40 | + occurrence_counts = [] |
| 41 | + for pattern in patterns: |
| 42 | + occurrence_counts.append(CountOccurrences(pattern, bwt, starts, occ_counts_before)) |
| 43 | + print(' '.join(map(str, occurrence_counts))) |
0 commit comments