#P5840. [COCI 2014/2015 #5] Divljak

    ID: 6589 远端评测题 4000ms 768MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015线段树树状数组AC 自动机差分COCI(克罗地亚)

[COCI 2014/2015 #5] Divljak

Problem Description

Alice has nn strings S1,S2,,SnS_1, S_2, \dots, S_n, and Bob has a set of strings TT, which is empty at the beginning.

Then there will be qq operations. There are two types of operations:

  1. 1 P: Bob adds a string PP to his set.
  2. 2 x: Alice asks Bob how many strings in set TT contain the string SxS_x (we say string AA contains string BB if and only if BB is a substring of AA).

Input Format

The first line contains an integer nn.

The next nn lines each contain a string Si{S}_i.

The next line contains an integer qq.

The next qq lines each contain one operation.

Output Format

For each 2 x operation, output one integer per line, representing the answer.

3
a
bc
abc
5
1 abca
2 1
1 bca
2 2
2 3

1
2
1

Hint

For 50%50\% of the testdata, n20000n \le 20000.

For 100%100\% of the testdata, 1n,q1051 \le n, q \le 10^5. All strings consist of lowercase letters. The sum of lengths of all strings in SS and the sum of lengths of all strings PP are each 2×106\le 2 \times 10^6.

Translated from COCI 2014/2015 CONTEST #5

Translated by ChatGPT 5