#P7140. [THUPC 2021 初赛] 区间矩阵乘法
[THUPC 2021 初赛] 区间矩阵乘法
Description
You are given a sequence of length . There are queries. Each query gives . Compute
$$\sum_{i=0}^{d-1} \sum_{j=0}^{d-1} \sum_{k=0}^{d-1} a_{p_1+d\cdot i+j} a_{p_2 + d\cdot j + k}$$Input Format
The first line contains an integer .
The next line contains integers, representing the sequence .
The next line contains an integer .
The next lines each contain three integers , describing one query.
Constraints: . All values are integers within . The queries guarantee that the indices of are within .
Output Format
Output lines, each being the answer to the corresponding query, taken modulo .
5
2 2 1 2 1
4
1 5 4
2 2 1
2 1 1
1 5 5
2
22
24
1
Hint
[Source]
From the THUPC2021 Preliminary Round of the 2021 Tsinghua University Student Algorithm Competition and University Invitational Contest (THUPC2021).
Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5
京公网安备 11011102002149号