#P7983. Sequence Operations and Prefix Sum Query

    ID: 21167 Type: Default 1000ms 256MiB

Sequence Operations and Prefix Sum Query

Sequence Operations and Prefix Sum Query

Given two sequences \(a\) and \(b\) of length \(n\), you are to support \(m\) operations on the sequences. The operations can be one of the following three types:

  • 1 l r x: Set every element in the subarray \(a[l \ldots r]\) to \(x\);
  • 2 l r y: Set every element in the subarray \(b[l \ldots r]\) to \(y\);
  • 3 l r: Compute \[ \sum_{i=l}^{r} \left( \sum_{j=1}^{b_i} a_j \right) \mod 2^{32} \] where \(b_i\) denotes the \(i\)th element of the sequence \(b\). Note that the inner sum is taken over the first \(b_i\) elements of \(a\).

Operations are performed in the order they are given and may affect subsequent queries. It is guaranteed that for all operations of type 3, the value \(b_i\) will not exceed \(n\) (i.e. \(1 \le b_i \le n\)).

inputFormat

The first line contains two integers \(n\) and \(m\) \( (1 \leq n, m \leq \text{small constraints})\), representing the length of the sequences and the number of operations respectively.

The second line contains \(n\) integers, representing the initial sequence \(a\).

The third line contains \(n\) integers, representing the initial sequence \(b\). It is guaranteed that \(1 \le b_i \le n\) for all \(i\).

The next \(m\) lines each describe an operation in one of the following formats:

  • 1 l r x
  • 2 l r y
  • 3 l r

outputFormat

For each operation of type 3, output one line containing the answer (the computed sum modulo \(2^{32}\)).

sample

4 5
1 2 3 4
1 2 3 4
3 1 4
1 2 3 10
3 1 4
2 3 4 2
3 1 4
20

58 34

</p>