QOJ.ac

QOJ

时间限制: 1.5 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#18688. 普塔塔反击

统计

Putata 热爱字符串问题。如今,他将传统的字符串问题重新带回了竞赛编程。他的宿敌 Budada 试图证明所有字符串问题都是平凡的。现在,你需要解决 Putata 提出的这个问题,以证明他的论断。

给定三个字符串序列 $P, Q$ 和 $R$,长度分别为 $n, m$ 和 $k$。序列中的每个元素都是一个字符串。例如,如果 $P=\{\textt{ab},\texttt{bcd}\}$,则 $P_1=\texttt{ab}$,$P_2=\texttt{bcd}$。求满足下列条件的非空字符串对 $(A,B)$ 的数量:

  • $\exists i\in[1,n]$,使得 $A$ 是 $P_i$ 的前缀。
  • $\exists i\in[1,m]$,使得 $B$ 是 $Q_i$ 的后缀。
  • $\exists i\in[1,k]$,使得 $AB$ 是 $R_i$ 的子串。

称长度为 $n$ 的字符串 $A$ 是长度为 $m$ 的字符串 $B$ 的前缀,当且仅当 $n\leq m$ 且 $\forall i\in [1,n]$,$A_i=B_i$。

称长度为 $n$ 的字符串 $A$ 是长度为 $m$ 的字符串 $B$ 的后缀,当且仅当 $n\leq m$ 且 $\forall i\in [1,n]$,$A_i=B_{m-n+i}$。

称长度为 $n$ 的字符串 $A$ 是长度为 $m$ 的字符串 $B$ 的子串,当且仅当 $n\leq m$ 且 $\exists j\in [0,m-n]$,使得 $\forall i\in [1,n]$,$A_i=B_{j+i}$。

将长度为 $n$ 的字符串 $A$ 和长度为 $m$ 的字符串 $B$ 拼接得到 $AB$,它是一个长度为 $n+m$ 的字符串,满足当 $i\in [1,n]$ 时 $AB_{i}=A_i$,否则 $AB_{i}=B_{i-n}$。

两对字符串 $(A,B)$ 和 $(C,D)$ 被视为不同,当且仅当 $A\neq C$ 或 $B\neq D$。

输入格式

第一行包含三个整数 $n,m$ 和 $k$($1\leq n,m,k\leq 3\times 10^5$),表示序列 $P, Q$ 和 $R$ 的长度。

接下来的 $n$ 行中,第 $i$ 行包含一个字符串 $P_i$($1\leq |P_i|\leq 3\times 10^5$)。

接下来的 $m$ 行中,第 $i$ 行包含一个字符串 $Q_i$($1\leq |Q_i|\leq 3\times 10^5$)。

接下来的 $k$ 行中,第 $i$ 行包含一个字符串 $R_i$($1\leq |R_i|\leq 3\times 10^5$)。

保证所有字符串仅由小写英文字母组成。

保证 $1\leq \sum|P_i|,\sum|Q_i|,\sum|R_i|\leq 3\times 10^5$。

输出格式

输出一个整数,表示答案。

样例

样例输入 1

1 1 1
pb
pb
ppb

样例输出 1

2

样例输入 2

2 2 2
putata
budada
oipotato
suikapredator
putato
budapredatortato

样例输出 2

8

样例输入 3

2 2 1
aba
abc
bac
bca
abcabc

样例输出 3

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.