#P3932. 浮游大陆的68号岛
浮游大陆的68号岛
Description
Golden fairies live in the Fairy Warehouse. They live happily, yet are always ready to face death.
Put more nobly, they are always ready to sacrifice themselves for this hopeless world.
However, children always live carefree lives. The young golden fairies live innocently and naturally have no time to think about heavy duties like saving the world.

One day, the little fairies are playing a game again. The game goes like this.
The storage points of the Fairy Warehouse can be regarded as lying on a number line. Each storage point has some items, and there are distances between them.
Each time they pick one little fairy, and the others collect all the items at the storage points in the interval . After counting, they ask her: what is the cost to move all items from storage points in this interval to another storage point?
For example, if storage point has items and you want to move them to storage point , the cost is
Here, is the distance between storage points.
Of course, since the little fairies cannot handle very large numbers, your answer needs to be taken modulo .

Input Format
The first line contains two integers .
The second line contains integers. The -th number is the distance between storage points and .
The third line contains integers, giving the number of items at each storage point.
Then follow lines, each containing three integers x l r.
Each query asks for the cost to move all items from storage points in the interval to storage point .
Output Format
For each query, output one integer: the answer.
5 5
2 3 4 5
1 2 3 4 5
1 1 5
3 1 5
2 3 3
3 3 3
1 5 5
125
72
9
0
70
Hint
- For of the testdata, .
- For another of the testdata, all distances between storage points are .
- For another of the testdata, the number of items at every storage point is .
- For of the testdata, ; all distances and item counts are at most .
Translated by ChatGPT 5
京公网安备 11011102002149号