#P10516. Sequence Operations and Queries
Sequence Operations and Queries
Sequence Operations and Queries
Given two sequences of integers, \(a_i\) and \(b_i\), each of length \(n\), you need to process \(q\) queries of three types:
- Update by condition: Given an interval \([l, r]\) and two integers \(k\) and \(t\), for each index \(i\) in \([l, r]\) (1-indexed) such that \(a_i \times b_i \le k\) (i.e. \(a_i \times b_i \leq k\)), add \(t\) to both \(a_i\) and \(b_i\).
- Point update: Given an index \(i\) and two integers \(x\) and \(y\), update \(a_i = x\) and \(b_i = y\).
- Range query: Given an interval \([l, r]\), output the sum \(\sum_{i=l}^{r} (a_i+b_i)\).
All indices in the queries are 1-indexed.
Note: The constraints are such that a straightforward simulation is acceptable.
inputFormat
The first line contains two integers \(n\) and \(q\) -- the length of the sequences and the number of queries.
The second line contains \(n\) integers representing the sequence \(a_1, a_2, \ldots, a_n\).
The third line contains \(n\) integers representing the sequence \(b_1, b_2, \ldots, b_n\).
The next \(q\) lines each represent a query in one of the following formats:
- For query type 1:
1 l r k t
- For query type 2:
2 i x y
- For query type 3:
3 l r
outputFormat
For each query of type 3, output the corresponding sum \(\sum_{i=l}^{r} (a_i+b_i)\) on a separate line.
sample
5 5
1 2 3 4 5
5 4 3 2 1
3 1 5
1 2 4 10 1
3 1 5
2 3 10 10
3 1 5
30
35
48
</p>