QOJ.ac

QOJ

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

#18688. 普塔塔反擊

통계

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$ 的前綴
  • $\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.