#P4692. [Ynoi Easy Round 2016] 谁的梦

    ID: 3644 远端评测题 1500ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016O2优化容斥概率论,统计Ynoi

[Ynoi Easy Round 2016] 谁的梦

Description

You are playing a galgame when the power suddenly goes out. You run to the property management office to ask, and find out it was because a bald guy kicked the transformer, and it may take a long time to fix. So you decide to think about a data structure problem you saw before:

Define the weight of a sequence as the number of distinct numbers in it. For example, [1,2,3,3][1,2,3,3] has weight 33.

Now there are nn sequences. For each sequence, we choose a non-empty contiguous substring, and concatenate them. Compute the sum of the weights of the resulting sequence over all choices.

If a sequence can be obtained in multiple ways, count it multiple times.

This problem includes modification operations; see the input format.

Since the result may be too large, output the answer mod19260817\bmod 19260817.

Input Format

The first line contains two integers n,mn,m, meaning there are nn sequences and mm modifications.

The second line contains nn integers; the ii-th number is lenilen_i, meaning the length of the ii-th sequence.

Then follow nn lines; the ii-th line contains lenilen_i integers, representing the ii-th sequence.

Then follow mm lines; each line contains three integers x,y,zx,y,z, meaning change the yy-th element of the xx-th sequence to zz.

Output Format

Output m+1m + 1 lines, each containing one integer, representing the answer for the initial state and after each modification, in order.

2 5
6 6
1 3 1 1 3 2 
2 3 3 2 1 1 
1 1 1
1 1 2
1 1 2
1 1 1
1 1 1
1158
1158
1168
1168
1158
1158

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477 ( partially uploaded )

1n,m,leni1051 \leq n,m,len_i \leq 10^5. The elements in the sequences are all 3232-bit integers, and leni105\sum len_i \leq 10^5.

There are 5050 test cases.

Translated by ChatGPT 5