CF1921F.Sum of Progression
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
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.
给你一个包含 n 个数字的数组 a。此外还有 q 个形如 s,d,k 的查询。
对于每个查询 q,求和式 as+as+d⋅2+⋯+as+d⋅(k−1)⋅k 的值。换言之,对每个查询,需从第 s 个元素开始,以步长 d 取出数组中的 k 个元素,并将每个元素乘以其在所取序列中的序号(从 1 开始编号),最后求和。
输入格式
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 $.
每个测试包含若干测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来的行描述各测试用例。
每个测试用例的第一行包含两个整数 n,q(1≤n≤105, 1≤q≤2⋅105),分别表示数组 a 的元素个数和查询次数。
第二行包含 n 个整数 a1,…,an(−108≤a1,…,an≤108),即数组 a 的元素。
接下来的 q 行,每行包含三个整数 s、d 和 k(1≤s,d,k≤n,且满足 s+d⋅(k−1)≤n)。
保证所有测试用例的 n 之和不超过 105,且所有测试用例的 q 之和不超过 2⋅105。
输出格式
For each testcase, print q numbers in a separate line — the desired sums, separated with space.
对于每个测试用例,在单独一行中输出 q 个数字——即所求的和,各数字之间用空格分隔。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?