幽默的世界。

Luogu
IDLGP9681
Time1000ms
Memory512MB
DifficultyP4
洛谷原创O2优化前缀和洛谷月赛
给定一个长为 $n$ 的序列 $a_1,a_2,\cdots,a_n$,定义 $a$ 的一个连续子序列 $a_l,a_{l+1},\cdots,a_r$ 是幽默的,当且仅当: - $\sum\limits_{i=l}^ra_i>0$; - 对于所有 $l\le x\le y<r$,满足 $\sum\limits_{i=x}^y a_i\le 0$。 $q$ 次询问,每次给定两个整数 $l,r$,查询满足以下条件的数对 $(l',r')$ 个数: - $l\le l'\le r'\le r$; - 连续子序列 $a_{l'},a_{l'+1},\cdots a_{r'}$ 是幽默的。 ## Input 第一行输入两个整数 $n,q$。 接下来一行输入 $n$ 个整数,第 $i$ 个整数代表 $a_i$。 接下来 $q$ 行,每行输入两个整数 $l,r$,代表一次询问。 ## Output 对于每组询问,输出一行一个整数,代表答案。 [samples] ## Background @【数据删除】 : 大家觉得呢 || @【数据删除】 : oi 生活总是充满了幽默。 不过学文化课或许也好不了多少? ## Note 对于所有数据,保证 $1\le n,q\le 2\times 10^5$,$1\le l\le r\le n$,$|a_i|\le 10^9$。 ### 子任务 | # | 特殊性质 | 分值 | | :--: | :-------------------: | :--: | | 0 | 样例 | 0 | | 1 | $n,q\le 50$ | 15 | | 2 | $n,q\le 3\times 10^3$ | 20 | | 3 | 对于所有询问,$r=n$ | 15 | | 4 | 对于所有询问,$l=1$ | 15 | | 5 | - | 35 |
Samples
Input #1
4 3
3 -4 -1 2
1 2
3 4
1 4
Output #1
1
2
3
Input #2
7 6
-1 2 -1 -1 -1 2 -1
2 5
4 7
1 7
5 5
1 3
2 4
Output #2
1
2
4
0
2
1
API Response (JSON)
{
  "problem": {
    "name": "幽默的世界。",
    "description": {
      "content": "给定一个长为 $n$ 的序列 $a_1,a_2,\\cdots,a_n$,定义 $a$ 的一个连续子序列 $a_l,a_{l+1},\\cdots,a_r$ 是幽默的,当且仅当: - $\\sum\\limits_{i=l}^ra_i>0$; - 对于所有 $l\\le x\\le y<r$,满足 $\\sum\\limits_{i=x}^y a_i\\le 0$。 $q$ 次询问,每次给定两个整数 $l,r$",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P4"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP9681"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定一个长为 $n$ 的序列 $a_1,a_2,\\cdots,a_n$,定义 $a$ 的一个连续子序列 $a_l,a_{l+1},\\cdots,a_r$ 是幽默的,当且仅当:\n\n- $\\sum\\limits_{i=l}^ra_i>0$;\n- 对于所有 $l\\le x\\le y<r$,满足 $\\sum\\limits_{i=x}^y a_i\\le 0$。\n\n$q$ 次询问,每次给定两个整数 $l,r$...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments