Sum Zero

아직 제출이 없습니다시간 제한0.6초메모리 제한1024 MB

문제

Roxy, the space traveler, is facing a very abstract problem. Since she’s clueless as to how to solve it, you, as her best friend, have no choice but to help her out:

She is given an array c_1,c_2,,c_Nc\_1, c\_2, \dots , c\_N consisting of NN integers, and QQ pairs of endpoints (L_i,R_i)(L\_i , R\_i), each representing the subarray c_L_i,c_L_i+1,,c_R_ic\_{L\_i} , c\_{L\_i+1}, \dots , c\_{R\_i}, where 1iN1 ≤ i ≤ N.

For each such pair (L_i,R_i)(L\_i , R\_i), Roxy is asked what is the maximum number of disjoint sum-0 subarrays one can choose from the queried array c_L_i,c_L_i+1,,c_R_ic\_{L\_i} , c\_{L\_i+1}, \dots , c\_{R\_i}. Two subarrays are considered disjoint if they have no entries in common; however, they can still have neighboring endpoints. Note that, there might be entries from the queried array that are not part of any of the chosen subarrays.

입력

The first line of the input contains a single integer NN.

The second line contains NN space-separated integers c_1,c_2,,c_Nc\_1, c\_2, \dots , c\_N.

The third line contains the number QQ of queries.

The next QQ lines contain two numbers L_iL\_i and R_iR\_i each, representing the iith query.

출력

Print QQ lines: on the iith line you should print the answer to the iith query.

제한

  • 1N400,0001 ≤ N ≤ 400\\,000
  • 1Q400,0001 ≤ Q ≤ 400\\,000
  • 109c_i109−10^9 ≤ c\_i ≤ 10^9 for all 1iN1 ≤ i ≤ N
  • 1L_iR_iN1 ≤ L\_i ≤ R\_i ≤ N for all 1iQ1 ≤ i ≤ Q