#P7582. 「RdOI R2」风雨(rain)

    ID: 6202 远端评测题 2000ms 64MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>树状数组2021O2优化块状链表,块状数组,分块AC 自动机KMP

「RdOI R2」风雨(rain)

Description

During this period, Little Soup recorded nn meaningful things, and represented them with strings. The ii-th thing is represented as sis_i, and its value is defined as aia_i. Next, Little Soup will perform mm operations.

Operation 1: Little Soup adds a constant kk to all aia_i in the interval [l,r][l, r].

Operation 2: Little Soup assigns all aia_i in the interval [l,r][l, r] to a constant kk.

Operation 3: Little Soup gives a memory, which forms a string SS. He wants to know how meaningful SS is within the interval [l,r][l, r]. Let cnticnt_i be the number of occurrences of sis_i in SS. Then the meaning of SS in the interval [l,r][l, r] is i=lrcnti×ai\sum\limits_{i=l}^r cnt_i \times a_i.

Input Format

The first line contains two integers n,mn, m.

The next nn lines: the ii-th line contains a string sis_i and an integer aia_i.

The next mm lines: each line describes one operation, starting with three integers op,l,rop, l, r, where opop denotes the operation type. When op=3op = 3, an additional string SS is given; otherwise, an additional integer kk is given.

Output Format

For each operation of type 33, output one integer, representing the total value.

3 4
ab 1
ba 2
a 1
3 1 3 aba
1 1 2 1
2 2 3 2
3 1 2 abab
5
6
6 6
aba 3
ba 2
aa 2
c 1
abac 4
ab 2
3 2 5 abac
2 3 5 3
3 4 6 abc
1 2 3 1
3 1 3 aabaa
3 2 5 aabac
7
5
14
13
6 3
b 1
aa 8
cc 9
cac 8
ab 10
a 7
2 1 3 2
3 1 4 acac
3 1 6 ccaba
8
28

Hint

Sample 1 Explanation

For the first query, s1s_1 appears 11 time and contributes 11 to the value; s2s_2 appears 11 time and contributes 22; s3s_3 appears 22 times and contributes 22. The total value is 55.

For the second query, s1s_1 appears 22 times and contributes 44; s2s_2 appears 11 time and contributes 22. The total value is 66.


Constraints

Test ID s,S\sum s, \sum S n,mn, m Special Property
121 \sim 2 5×103\le 5 \times 10^3 10310^3 \diagdown
343 \sim 4 2×105\le 2 \times 10^5 3×1043 \times 10^4 No operation 11
585 \sim 8 No operations 1,21, 2
9139 \sim 13 \diagdown

For 100%100\% of the testdata, 1n,m3×1041 \le n, m \le 3 \times 10^4, k1k \ge 1, S,s2×105\sum |S|, \sum |s| \le 2 \times 10^5. At any time, 1ai2×1041 \le a_i \le 2 \times 10^4. It is guaranteed that only the three characters a,b,ca, b, c will appear.

Translated by ChatGPT 5