QOJ.ac

QOJ

Limite de temps : 1.5 s Limite de mémoire : 128 MB Points totaux : 100

#9088. Whose Dream

Statistiques

The weight of a sequence is defined as the number of distinct elements in it. For example, the weight of $[1, 2, 3, 3]$ is $3$.

Given $n$ sequences, we choose one non-empty contiguous substring from each sequence and concatenate them. Calculate the sum of the weights of all sequences formed by all possible choices.

If a sequence can be formed in multiple ways, it is counted multiple times.

This problem includes modification operations; please refer to the input format for details.

Since the result may be very large, output the answer modulo $19260817$.

Input

The first line contains two integers $n$ and $m$, representing $n$ sequences and $m$ modifications.

The second line contains $n$ integers, where the $i$-th integer is $len_i$, the length of the $i$-th sequence.

The next $n$ lines each contain $len_i$ integers, representing the $i$-th sequence.

The following $m$ lines each contain three integers $x, y, z$, indicating that the $y$-th element of the $x$-th sequence is changed to $z$.

Output

Output $m + 1$ lines, each containing an integer, representing the answer for the initial state and after each modification, respectively.

Examples

Input 1

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

Output 1

1158
1158
1168
1168
1158
1158

Subtasks

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

$1 \leq n, m, len_i \leq 10^5$, elements in the sequences are 32-bit integers, $\sum len_i \leq 10^5$.

There are 50 test cases in total.

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.