QOJ.ac

QOJ

시간 제한: 1.5 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#18688. Putata Strikes Back

통계

Putata は文字列問題が大好きです。彼は伝統的な文字列問題を競技プログラミングに再び持ち込みました。彼の宿敵である Budada は、すべての文字列問題は自明であることを証明しようとしています。あなたは Putata が提案したこの問題を解いて、彼の主張を証明する必要があります。

三つの文字列列 $P, Q, R$ が与えられます。それぞれの長さは $n, m, k$ です。文字列列の各要素は文字列です。例えば、$P=\{\texttt{ab},\texttt{bcd}\}$ ならば、$P_1=\texttt{ab}$, $P_2=\texttt{bcd}$ となります。以下の条件をすべて満たす空でない文字列の組 $(A,B)$ の個数を求めてください。

  • $\exists i\in[1,n]$ が存在し、$A$ は $P_i$ の接頭辞(prefix)である。
  • $\exists i\in[1,m]$ が存在し、$B$ は $Q_i$ の接尾辞(suffix)である。
  • $\exists i\in[1,k]$ が存在し、$AB$ は $R_i$ の部分文字列(substring)である。

長さ $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$) が与えられます。

すべての文字列は英小文字のみからなることが保証されています。

$\sum|P_i|,\sum|Q_i|,\sum|R_i|$ はすべて $1$ 以上 $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.