Logo
(追記) (追記ここまで)

27368번 - Sum Zero 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.6 초 1024 MB42161555.556%

문제

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, \dots , c_N$ consisting of $N$ integers, and $Q$ pairs of endpoints $(L_i , R_i),ドル each representing the subarray $c_{L_i} , c_{L_i+1}, \dots , c_{R_i},ドル where 1ドル ≤ i ≤ N$.

For each such pair $(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}, \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 $N$.

The second line contains $N$ space-separated integers $c_1, c_2, \dots , c_N$.

The third line contains the number $Q$ of queries.

The next $Q$ lines contain two numbers $L_i$ and $R_i$ each, representing the $i$th query.

출력

Print $Q$ lines: on the $i$th line you should print the answer to the $i$th query.

제한

  • 1ドル ≤ N ≤ 400,000円$
  • 1ドル ≤ Q ≤ 400,000円$
  • $−10^9 ≤ c_i ≤ 10^9$ for all 1ドル ≤ i ≤ N$
  • 1ドル ≤ L_i ≤ R_i ≤ N$ for all 1ドル ≤ i ≤ Q$

서브태스크 1 (22점)

  • 1ドル ≤ N ≤ 5,000円$
  • 1ドル ≤ Q ≤ 5,000円$

서브태스크 2 (39점)

  • 1ドル ≤ N ≤ 100,000円$
  • 1ドル ≤ Q ≤ 100,000円$

서브태스크 3 (39점)

  • No additional constraints.

예제 입력 1

10
1 2 -3 0 1 -4 3 2 -1 1
3
1 10
1 5
2 9

예제 출력 1

4
2
2

힌트

출처

Olympiad > Romanian Master of Informatics > Romanian Master of Informatics 2020 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /