#P9196. [JOI Open 2016] 销售基因链 / Selling RNA Strands
[JOI Open 2016] 销售基因链 / Selling RNA Strands
Background
Translated from JOI Open 2016 T2 "RNA 鎖の販売 / Selling RNA Strands".
Problem Description
There are strings in a gene database. These strings consist only of A, G, U, C (it is guaranteed that every string contains only these four letters).
There are queries. Each query contains two strings . You need to find: how many strings in the gene database have prefix and suffix at the same time.
For example, GAC has prefixes G, GA, GAC, and it has suffixes C, AC, GAC. So we can say: GAC has prefix GA and suffix AC at the same time.
Input Format
The input has lines.
The first line contains two integers .
In the next lines, each line contains one string , representing a string in the gene database.
In the next lines, each line contains two strings separated by a space, representing one query.
Output Format
Output lines. Each line contains one integer, the number of strings that satisfy the query conditions.
2 3
AUGC
AGC
G C
AU C
A C
0
1
2
3 3
AA
AA
AGA
AA AA
AG GA
AG GA
2
1
1
8 7
GCGCUACCCCAACACAAGGCAAGAUAUA
G
GGAC
GCGG
U
GCGCUACCCCAACACAAGGCAAGAUGGUC
GCCG
GCGCUGA
GCGCUACCC A
GCGCUACCCC AC
GCG C
GCGC A
G G
G C
G GGA
1
0
1
2
3
2
0
Hint
Explanation for Sample 1
Query 1: cannot find any;
Query 2: AUGC satisfies the conditions;
Query 3: AUGC and AGC satisfy the conditions.
Explanation for Sample 2
Note that strings in the gene database may be repeated.
Constraints
This problem uses bundled testdata.
For all testdata, , , $1\le\sum |S_i|, \sum |P_j|, \sum |Q_j| \le 2\times 10^6$.
- Subtask 1 (10 points): .
- Subtask 2 (25 points): .
- Subtask 3 (25 points): .
- Subtask 4 (40 points): no additional constraints.
Translated by ChatGPT 5