ΣexAI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a length-$N$ sequence of non-negative integers $A = (A_1, \dots, A_N)$.
给定一个长度为 $N$ 的非负整数序列 $A = (A_1, \dots, A_N)$。AI (CI翻译)
Find the sum of $\mathrm{mex}({A_l, \cdots, A_r})$ over all pairs of integers $(l, r)$ satisfying $1 \leq l \leq r \leq N$.
求满足 $1 \leq l \leq r \leq N$ 的所有整数对 $(l, r)$ 对应的 $\mathrm{mex}({A_l, \cdots, A_r})$ 之和。AI (CI翻译)
Here, $\mathrm{mex}({A_l, \cdots, A_r})$ denotes the smallest non-negative integer not contained in $A_l, \cdots, A_r$.
其中,$\mathrm{mex}({A_l, \cdots, A_r})$ 表示未包含在 $A_l, \cdots, A_r$ 中的最小非负整数。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq N \leq 3 \times 10^5$$0 \leq A_i \leq N$- All input values are integers.
$1 \leq N \leq 3 \times 10^5$$0 \leq A_i \leq N$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入通过标准输入按以下格式给出:AI (CI翻译)
N
A_1 A_2 \cdots A_N
N
A_1 A_2 \cdots A_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer.
输出答案。AI (CI翻译)
样例
3
1 2 0
5
6
2 1 0 2 1 4
31
25
2 2 1 2 2 0 2 2 2 1 2 2 2 0 2 2 2 2 1 2 2 2 2 0 2
624
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。