[DTCPC 2024] mex,min,max

Luogu
IDLGP10169
Time1500ms
Memory512MB
DifficultyP6
线段树2024颜色段均摊(珂朵莉树 ODT)洛谷月赛单调栈
给定序列 $\{a_n\}$ 和 $k$,求有多少子区间 $[l,r]$ 满足 $\operatorname{mex}\{a_l,a_{l+1},\dots,a_{r-1},a_r\}+\min\{a_l,a_{l+1},\dots,a_{r-1},a_r\}+k\geq \max\{a_l,a_{l+1},\dots,a_{r-1},a_r\}$。 $\operatorname{mex}$ 定义为集合内没有出现过的最小的**非负整数**。 ## Input 第一行两个整数 $n,k$($1\leq n\leq 5\times 10^5,0\leq k\leq n$)。 第二行 $n$ 个非负整数,第 $i$ 个表示 $a_i$($0\leq a_i\leq n$)。 ## Output 一行一个数,表示满足条件的子区间个数。 [samples]
Samples
Input #1
3 0
1 0 2
Output #1
5
API Response (JSON)
{
  "problem": {
    "name": "[DTCPC 2024] mex,min,max",
    "description": {
      "content": "给定序列 $\\{a_n\\}$ 和 $k$,求有多少子区间 $[l,r]$ 满足 $\\operatorname{mex}\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}+\\min\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}+k\\geq \\max\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}$。 $\\operatorname{mex}$ 定",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1500,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P6"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10169"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定序列 $\\{a_n\\}$ 和 $k$,求有多少子区间 $[l,r]$ 满足 $\\operatorname{mex}\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}+\\min\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}+k\\geq \\max\\{a_l,a_{l+1},\\dots,a_{r-1},a_r\\}$。\n\n$\\operatorname{mex}$ 定...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments