CF1921F.Sum of Progression
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of n numbers. There are also q queries of the form s,d,k .
For each query q , find the sum of elements as+as+d⋅2+⋯+as+d⋅(k−1)⋅k . In other words, for each query, it is necessary to find the sum of k elements of the array with indices starting from the s -th, taking steps of size d , multiplying it by the serial number of the element in the resulting sequence.
输入格式
Each test consists of several testcases. The first line contains one integer t ( 1≤t≤104 ) — the number of testcases. Next lines contain descriptions of testcases.
The first line of each testcase contains two numbers n,q ( 1≤n≤105,1≤q≤2⋅105 ) — the number of elements in the array a and the number of queries.
The second line contains n integers a1,...an ( −108≤a1,...,an≤108 ) — elements of the array a .
The next q lines each contain three integers s , d , and k ( 1≤s,d,k≤n , s+d⋅(k−1)≤n ).
It is guaranteed that the sum of n over all testcases does not exceed 105 , and that the sum of q over all testcases does not exceed $2 \cdot 10^5 $ .
输出格式
For each testcase, print q numbers in a separate line — the desired sums, separated with space.
输入输出样例
输入#1
5 3 3 1 1 2 1 2 2 2 2 1 1 1 2 3 1 -100000000 -100000000 -100000000 1 1 3 5 3 1 2 3 4 5 1 2 3 2 3 2 1 1 5 3 1 100000000 100000000 100000000 1 1 3 7 7 34 87 5 42 -44 66 -32 2 2 2 4 3 1 1 3 2 6 2 1 5 2 2 2 5 2 6 1 2
输出#1
5 1 3 -600000000 22 12 55 600000000 171 42 118 66 -108 23 2