8654: Mario Party

内存限制:128 MB 时间限制:20 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Mario Party is a classic board game featuring numerous minigames. In this game, players possess coins and aim to collect stars at particular positions. For simplicity, we treat the board as a 1 by n grid with grids labeled with 1 to n from left to right, and there is an integer a_iai in cell ii. Suppose a player is currently in the cell ii with xx coins. He may perform the following operation:

  1. Move to cell i+1, and the number of coins he possesses becomes  x+ai+1 if x+ai+10, and remains the same otherwise .

You have to answer q independent queries of the following form:

  1. Suppose a player is currently in cell ll with xx coins. Compute the number of coins he possesses after he travels to cell r by performing the above operations r-l times.

输入格式

The first line contains an integer T 1T4), denoting the number of test cases.

For each test case, the first line contains two integers n,q (1n,q5105), denoting the number of cells in the grid and the number of queries, respectively.

The second line of each test case contains n integers a1,a2,,an (i=1nai106).

Each of the following q lines contains integers li,ri,xi (1lirin0xi106), denoting the parameters of the i-th query.

输出格式

For each query in each test case, output an integer in one line, denoting the answer.

输入样例 复制

1
5 6
1 -2 3 -4 5
1 5 0
1 5 1
1 5 2
1 5 3
1 5 4
1 5 5

输出样例 复制

8
5
8
5
6
7