Zero-Sum Ranges

AtCoder
IDagc023_a
Time2000ms
Memory256MB
Difficulty
We have an integer sequence $A$, whose length is $N$. Find the number of the non-empty **contiguous** subsequences of $A$ whose sums are $0$. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $-10^9 \leq A_i \leq 10^9$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $...$ $A_N$ [samples]
Samples
Input #1
6
1 3 -4 2 2 -2
Output #1
3

There are three contiguous subsequences whose sums are $0$: $(1,3,-4)$, $(-4,2,2)$ and $(2,-2)$.
Input #2
7
1 -1 1 -1 1 -1 1
Output #2
12

In this case, some subsequences that have the same contents but are taken from different positions are counted individually. For example, three occurrences of $(1, -1)$ are counted.
Input #3
5
1 -2 3 -4 5
Output #3
0

There are no contiguous subsequences whose sums are $0$.
API Response (JSON)
{
  "problem": {
    "name": "Zero-Sum Ranges",
    "description": {
      "content": "We have an integer sequence $A$, whose length is $N$. Find the number of the non-empty **contiguous** subsequences of $A$ whose sums are $0$. Note that we are counting **the ways to take out subsequen",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc023_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have an integer sequence $A$, whose length is $N$.\nFind the number of the non-empty **contiguous** subsequences of $A$ whose sums are $0$. Note that we are counting **the ways to take out subsequen...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments