/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 333 点
問題文
高橋君は、広大な果樹園を管理しています。
この果樹園には N 本の果樹が一列に並んでおり、左から順に 1, 2, \ldots, N の番号が付けられています。果樹 i からは、1 時間あたり A_i 個の果実を収穫することができます。どの果樹にも十分な量の果実が実っているため、収穫時間によって果実が足りなくなることはありません。
高橋君は、収穫作業の計画を立てるために、以下の Q 個のクエリに答える必要があります。
j 番目のクエリでは、収穫範囲の左端 L_j、右端 R_j、および収穫時間 T_j が与えられます。果樹 L_j から果樹 R_j までの範囲にあるすべての果樹について、それぞれ T_j 時間の収穫を行います。果樹 i(L_j \leq i \leq R_j)からの収穫個数は A_i \times T_j 個です。この範囲全体で収穫できる果実の合計個数、すなわち
\sum_{i=L_j}^{R_j} A_i \times T_j
を求めてください。
なお、各クエリは独立であり、あるクエリでの収穫が他のクエリに影響することはありません。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^4 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq Q)
- 1 \leq T_j \leq 10^4 (1 \leq j \leq Q)
- 入力はすべて整数
入力
N Q A_1 A_2 \ldots A_N L_1 R_1 T_1 L_2 R_2 T_2 \vdots L_Q R_Q T_Q
- 1 行目には、果樹の本数を表す整数 N と、クエリの個数を表す整数 Q が、スペース区切りで与えられる。
- 2 行目には、各果樹の 1 時間あたりの収穫個数を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
- 続く Q 行にわたって、各クエリの情報が与えられる。
- 2 + j 行目では、j 番目のクエリにおける収穫範囲の左端 L_j、右端 R_j、収穫時間 T_j が、スペース区切りで与えられる。
出力
Q 行にわたって、各クエリの答えを整数で出力してください。j 行目には、j 番目のクエリに対する答え、すなわち果樹 L_j から果樹 R_j までの各果樹から T_j 時間で収穫できる果実の合計個数を出力してください。
入力例 1
5 3 2 5 3 1 4 1 3 2 2 5 3 1 1 5
出力例 1
20 39 10
入力例 2
7 5 10 20 30 40 50 60 70 1 7 1 3 5 2 1 4 3 6 7 4 4 4 10
出力例 2
280 240 300 520 400
入力例 3
10 8 100 200 150 300 250 400 350 500 450 600 1 10 1 1 5 2 6 10 3 3 7 5 1 1 100 5 5 50 2 9 10 1 10 10000
出力例 3
3300 2000 6900 7250 10000 12500 26000 33000000
Score : 333 pts
Problem Statement
Takahashi manages a vast orchard.
In this orchard, there are N fruit trees lined up in a row, numbered 1, 2, \ldots, N from left to right. From fruit tree i, A_i fruits can be harvested per hour. Each tree has a sufficient amount of fruit, so the supply never runs out regardless of the harvesting time.
Takahashi needs to answer the following Q queries to plan the harvesting work.
In the j-th query, the left endpoint L_j, right endpoint R_j of the harvesting range, and the harvesting time T_j are given. For all fruit trees in the range from tree L_j to tree R_j, harvesting is performed for T_j hours each. The number of fruits harvested from tree i (L_j \leq i \leq R_j) is A_i \times T_j. Find the total number of fruits that can be harvested across this entire range, namely
\sum_{i=L_j}^{R_j} A_i \times T_j
Note that each query is independent, and harvesting in one query does not affect any other query.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq Q \leq 2 \times 10^5
- 1 \leq A_i \leq 10^4 (1 \leq i \leq N)
- 1 \leq L_j \leq R_j \leq N (1 \leq j \leq Q)
- 1 \leq T_j \leq 10^4 (1 \leq j \leq Q)
- All inputs are integers
Input
N Q A_1 A_2 \ldots A_N L_1 R_1 T_1 L_2 R_2 T_2 \vdots L_Q R_Q T_Q
- The first line contains an integer N representing the number of fruit trees and an integer Q representing the number of queries, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the number of fruits that can be harvested per hour from each fruit tree, separated by spaces.
- The following Q lines provide the information for each query.
- The (2 + j)-th line contains the left endpoint L_j, right endpoint R_j of the harvesting range, and the harvesting time T_j for the j-th query, separated by spaces.
Output
Output the answer to each query as an integer over Q lines. On the j-th line, output the answer to the j-th query, namely the total number of fruits that can be harvested in T_j hours from all fruit trees from tree L_j to tree R_j.
Sample Input 1
5 3 2 5 3 1 4 1 3 2 2 5 3 1 1 5
Sample Output 1
20 39 10
Sample Input 2
7 5 10 20 30 40 50 60 70 1 7 1 3 5 2 1 4 3 6 7 4 4 4 10
Sample Output 2
280 240 300 520 400
Sample Input 3
10 8 100 200 150 300 250 400 350 500 450 600 1 10 1 1 5 2 6 10 3 3 7 5 1 1 100 5 5 50 2 9 10 1 10 10000
Sample Output 3
3300 2000 6900 7250 10000 12500 26000 33000000