#P4692. Galgame Power Outage and Data Structure Puzzle
Galgame Power Outage and Data Structure Puzzle
Galgame Power Outage and Data Structure Puzzle
In this problem, you are given n sequences. The weight of a sequence is defined as the number of distinct integers in it. For example, the weight of ( [1,2,3,3] ) is 3.
You are to choose one non-empty contiguous subarray from each sequence; then, you concatenate the chosen subarrays in order to form a new sequence. The weight of the new sequence is defined as the number of distinct integers present in it. Note that if the same resulting sequence can be obtained by different selections, its weight is counted once for each occurrence.
Additionally, the sequences are subject to modification operations.
More formally, suppose that for each sequence ( S_i ) (with ( 1 \le i \le n )) you have a total of ( T_i = \frac{m_i(m_i+1)}{2} ) contiguous non-empty subarrays (where ( m_i ) is the length of ( S_i )). Let ( A_i(d) ) be the number of contiguous subarrays in ( S_i ) that contain the number ( d ). Then, if you choose one contiguous subarray from each sequence independently, the total number of ways to choose is ( \prod_{i=1}^n T_i ). For a fixed number ( d ), it will be missing from the selected subarrays from sequence ( i ) in ( T_i - A_i(d) ) ways, so the number of selections in which ( d ) does not appear anywhere is ( \prod_{i=1}^n (T_i - A_i(d)) ). Thus, by linearity, the answer is given by:
[ \text{Answer} = \sum_{d \in U} \left( \prod_{i=1}^n T_i - \prod_{i=1}^n (T_i - A_i(d)) \right) \pmod{19260817}, ]
where ( U ) is the union of all numbers present in the sequences.
Your task is to process a sequence of operations. Each operation is either a query or an update. For each query, compute and output the answer as defined above modulo (19260817).
inputFormat
The input begins with an integer ( n ) indicating the number of sequences. For each of the next ( n ) lines, the sequence is described by an integer ( m_i ) (the length of the sequence) followed by ( m_i ) integers.
Then, an integer ( q ) is given representing the number of operations. Each of the following ( q ) lines is in one of the two formats:
- Query operation: a line containing a single character
Q
, asking to compute the current answer. - Modification operation: a line in the format
C i pos x
, meaning that in the ( i)-th sequence, the element at position ( pos ) (1-indexed) is changed to ( x ).
outputFormat
For each query operation (Q
), output a single line containing the sum of the weights of all possible sequences obtained by selecting one contiguous subarray from each sequence, computed modulo (19260817).
sample
1
3 1 2 1
2
Q
C 1 2 1
Q
7
3
</p>