Curious Queries

3.8

9 votes
Segment Trees, Advanced Data Structures, Data Structures
Problem

You are given an array of length . You are asked queries. Each query is of the form , and the answer is the sum of for all such that and .

Print an array of length such that is the answer to the query.

Input format

  • The first line of input contains a single integer , which denotes the number of test cases.
  • The first line of each test case contains two integers  and , denoting the length of the array and the number of queries, respectively.
  • The second line of each test case contains integers, denoting the array .
  • The following lines of each test case contains two integers denoting each query.

Output format

For each test case, print an array of length  separated by space such that is the answer to the query in a new line.

Constraints

 

Sample Input
2
4 2
6 7 2 5
2 2
3 1
4 2
1 2 3 4
3 1
2 0
Sample Output
13 0
7 5
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case :

  • For the first query, satisfy the given conditions. Therefore the sum is .
  • For the second query, no value of satisfies the given conditions. Therefore the sum is .
  • Thus, the answer is .

For test case :

  • For the first query, satisfy the given conditions. Therefore the sum is .
  • For the second query, satisfy the given conditions. Therefore the sum is .
  • Thus, the answer is .
Editor Image

?