CF1921F.Sum of Progression

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa of nn numbers. There are also qq queries of the form s,d,ks, d, k .

For each query qq , find the sum of elements as+as+d2++as+d(k1)ka_s + a_{s+d} \cdot 2 + \dots + a_{s + d \cdot (k - 1)} \cdot k . In other words, for each query, it is necessary to find the sum of kk elements of the array with indices starting from the ss -th, taking steps of size dd , 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 tt ( 1t1041 \le t \le 10^4 ) — the number of testcases. Next lines contain descriptions of testcases.

The first line of each testcase contains two numbers n,qn, q ( 1n105,1q21051 \le n \le 10^5, 1 \le q \le 2 \cdot 10^5 ) — the number of elements in the array aa and the number of queries.

The second line contains nn integers a1,...ana_1, ... a_n ( 108a1,...,an108-10^8 \le a_1, ..., a_n \le 10^8 ) — elements of the array aa .

The next qq lines each contain three integers ss , dd , and kk ( 1s,d,kn1 \le s, d, k \le n , s+d(k1)ns + d\cdot (k - 1) \le n ).

It is guaranteed that the sum of nn over all testcases does not exceed 10510^5 , and that the sum of qq over all testcases does not exceed $2 \cdot 10^5 $ .

输出格式

For each testcase, print qq 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
首页