Max's Anger Contest Series 2 P3 - Array Anger

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 3.0s
Java 5.0s
Python 5.0s
Memory limit: 1G

Author:
Problem type

To stave off his boredom from not having a Communication Credit next term, Wesley decided to yell at his array (the closest thing to an intern).

He will yell Q queries at his array, A, of N integers. The queries take the form OI L_i S_i, where his array will answer the first R that satisfies SiSum[Li,Ri] or N if no valid Ri exists (Sum[L,R] denotes the sum of elements from the 1-indexed [L,R] in the array).

Since no one wants to be Wesley's intern, you are voluntold to be the array.

Can you answer these queries to prevent more yelling?

Constraints

1N2×105

1Q5×105

1Ai5×103

1LiN

1Si109

Subtask 1 [30%]

1N,Q103

Subtask 2 [70%]

No additional constraints.

Input Specification

The first line will contain two integers, N and Q, the number of array elements and the number of queries, respectively.

The next line will contain N integers, Ai, the elements of the array.

The next Q lines will contain one of the above queries, Li and Si, the start of the query and the minimum sum of the subarray.

Output Specification

Output Q lines with Ri, the answers to the queries.

Sample Input

Copy
6 6
1 5 3 2 1 7
OI 1 50
OI 1 19
OI 4 1
OI 1 12
OI 1 10
OI 2 8

Sample Output

Copy
6
6
4
5
4
3

Comments

There are no comments at the moment.