#K33602. Chemical Container Queries

    ID: 25124 Type: Default 1000ms 256MiB

Chemical Container Queries

Chemical Container Queries

You are given two containers holding chemicals. The first container has N chemicals with corresponding frequencies given by the list \(A=[a_1,a_2,\dots,a_N]\) and the second container has frequencies given by the list \(B=[b_1,b_2,\dots,b_N]\). You will also be given Q queries. Each query is represented as a triple \((type, L, R)\) where \(L\) and \(R\) denote a 1-indexed range.

For each query, perform one of the following operations over the range from \(L\) to \(R\) (inclusive):

  • If \(type = 1\), compute \(\sum_{i=L}^{R} a_i \times b_i\).
  • If \(type = 2\), compute \(\sum_{i=L}^{R} \min(a_i, b_i)\).

Print the result for each query on a new line.

inputFormat

The input is read from stdin and has the following format:

N Q
a1 a2 ... aN
b1 b2 ... bN
query1_type query1_L query1_R
query2_type query2_L query2_R
... (Q queries in total)

Where:

  • N is the number of chemicals.
  • Q is the number of queries.
  • The next two lines are lists of N integers representing the frequencies in each container.
  • Each of the next Q lines contains three integers: query type, L, and R.

outputFormat

The output is written to stdout and for each query, print the result on a separate line.

## sample
5 3
3 1 4 1 5
2 7 1 8 2
1 1 3
2 2 5
1 1 5
17

5 35

</p>