#P9681. 幽默的世界。

    ID: 10675 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创O2优化前缀和洛谷月赛

幽默的世界。

Background

@【data deleted】: What do you all think? || @【data deleted】: OI life is always full of humor. But maybe studying school subjects is not much better?

Problem Description

Given a sequence a1,a2,,ana_1,a_2,\cdots,a_n of length nn, define a contiguous subsequence al,al+1,,ara_l,a_{l+1},\cdots,a_r to be humorous if and only if:

  • i=lrai>0\sum\limits_{i=l}^r a_i>0;
  • For all lxy<rl\le x\le y<r, we have i=xyai0\sum\limits_{i=x}^y a_i\le 0.

There are qq queries. In each query, you are given two integers l,rl,r, and you need to count the number of pairs (l,r)(l',r') that satisfy:

  • llrrl\le l'\le r'\le r;
  • The contiguous subsequence al,al+1,ara_{l'},a_{l'+1},\cdots a_{r'} is humorous.

Input Format

The first line contains two integers n,qn,q.

The next line contains nn integers, where the ii-th integer is aia_i.

The next qq lines each contain two integers l,rl,r, representing a query.

Output Format

For each query, output one integer per line, which is the answer.

4 3
3 -4 -1 2
1 2
3 4
1 4

1
2
3

7 6
-1 2 -1 -1 -1 2 -1
2 5
4 7
1 7
5 5
1 3
2 4

1
2
4
0
2
1

Hint

For all testdata, it is guaranteed that 1n,q2×1051\le n,q\le 2\times 10^5, 1lrn1\le l\le r\le n, and ai109|a_i|\le 10^9.

Subtasks

# Special Property Score
0 Sample 0
1 n,q50n,q\le 50 15
2 n,q3×103n,q\le 3\times 10^3 20
3 For all queries, r=nr=n 15
4 For all queries, l=1l=1
5 - 35

Translated by ChatGPT 5