CF1921F.Sum of Progression

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

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+d⋅2+⋯+as+d⋅(k−1)⋅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.

给你一个包含 nn 个数字的数组 aa。此外还有 qq 个形如 s,d,ks, d, k 的查询。

对于每个查询 qq,求和式 as+as+d⋅2+⋯+as+d⋅(k−1)⋅ka_s + a_{s+d} \cdot 2 + \dots + a_{s + d \cdot (k - 1)} \cdot k 的值。换言之,对每个查询,需从第 ss 个元素开始,以步长 dd 取出数组中的 kk 个元素,并将每个元素乘以其在所取序列中的序号(从 11 开始编号),最后求和。

输入格式

Each test consists of several testcases. The first line contains one integer tt (1≤t≤1041 \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 (1≤n≤105,1≤q≤2⋅1051 \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 (−108≤a1,...,an≤108-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 (1≤s,d,k≤n1 \le s, d, k \le n, s+d⋅(k−1)≤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 $.

每个测试包含若干测试用例。第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。接下来的行描述各测试用例。

每个测试用例的第一行包含两个整数 n,qn, q(1≤n≤105, 1≤q≤2⋅1051 \le n \le 10^5,\ 1 \le q \le 2 \cdot 10^5),分别表示数组 aa 的元素个数和查询次数。

第二行包含 nn 个整数 a1,…,ana_1, \dots, a_n(−108≤a1,…,an≤108-10^8 \le a_1, \dots, a_n \le 10^8),即数组 aa 的元素。

接下来的 qq 行,每行包含三个整数 ss、dd 和 kk(1≤s,d,k≤n1 \le s, d, k \le n,且满足 s+d⋅(k−1)≤ns + d\cdot (k - 1) \le n)。

保证所有测试用例的 nn 之和不超过 10510^5,且所有测试用例的 qq 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print qq numbers in a separate line — the desired sums, separated with space.

对于每个测试用例,在单独一行中输出 qq 个数字——即所求的和,各数字之间用空格分隔。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页