#P2442. 分数统计

分数统计

Description

Yellow_sword asks Da Ning to build a database to maintain the class exam averages. Each student’s scores for the midterm subjects have been unified into a single rating, an integer in [1,100][1, 100]. This rating evaluates a student’s overall level. Now Yellow_sword has given Da Ning the average rating of nn classes and the size of each class. Because both Yellow_sword and Da Ning are lazy, they will assume every student in a class has a rating equal to that class’s average rating. He wants to know:

  1. The average rating of all students over some consecutive classes.
  2. The mode of all students’ ratings over some consecutive classes (if there are multiple, output the smallest mode).
  3. The range of all students’ ratings over some consecutive classes (that is, the difference between the highest and lowest ratings).

Since everyone is lazy, the task is given to you.

Input Format

The first line contains two integers nn and qq, the number of classes and the number of queries.

The second line contains nn integers aia_i, the average rating of the ii-th class.

The third line contains nn integers bib_i, the size of the ii-th class.

The next qq lines each contain one query in the format: Opt u v.

This means to query the item corresponding to Opt[1,3]Opt \in [1, 3] over classes from uu to vv, as described above.

Output Format

For each query, output the corresponding result on its own line. For the average, print exactly two decimal places, rounded down (floor).

5 3
90 100 90 90 80
2 1 2 1 8
1 1 3
2 3 5
3 1 2

92.00
80
10

Hint

For 100%100\% of the testdata, it is guaranteed that 1ai1001 \le a_i \le 100, 1bi1001 \le b_i \le 100.

Test point Scale Time limit
131 \sim 3 n=q=103n = q = 10^3 0.5 s0.5 \text{ s}
454 \sim 5 n=q=5×104n = q = 5 \times 10^4
676 \sim 7 n=q=105n = q = 10^5 1 s1 \text{ s}
8108 \sim 10 n=q=2×105n = q = 2 \times 10^5

It is recommended to use fast I/O.

Translated by ChatGPT 5