#P2344. [USACO11FEB] Generic Cow Protests G

    ID: 1316 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2011USACO树状数组离散化前缀和

[USACO11FEB] Generic Cow Protests G

Description

Farmer John's NN cows (1N1051 \leq N \leq 10^5) stand in a line, holding a protest. The ii-th cow has a sanity value aia_i (104ai104-10^4 \leq a_i \leq 10^4).

FJ wants the protest to stay rational. He will partition all cows into several groups so that, in each group, the sum of sanity values is at least zero.

Because the cows stand on a line, cows in one group must occupy a contiguous segment. Please compute how many grouping schemes satisfy the condition.

Input Format

The first line contains an integer NN.

The next NN lines each contain one integer; the ii-th line gives aia_i, the sanity value of the ii-th cow.

Output Format

Output the number of valid grouping schemes modulo 109+910^9 + 9.

4
2
3
-3
1
4

Hint

For example, for the sequence 2,3,3,12, 3, -3, 1, all valid grouping schemes are as follows:

  • (2 3 -3 1)\texttt{(2 3 -3 1)}
  • (2 3 -3) (1)\texttt{(2 3 -3) (1)}
  • (2) (3 -3 1)\texttt{(2) (3 -3 1)}
  • (2) (3 -3) (1)\texttt{(2) (3 -3) (1)}

Translated by ChatGPT 5