AT_abc470_g.Σex

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a length-NN sequence of non-negative integers A=(A1,…,AN)A = (A_1, \dots, A_N).

Find the sum of mex(Al,⋯ ,Ar)\mathrm{mex}({A_l, \cdots, A_r}) over all pairs of integers (l,r)(l, r) satisfying 1≤l≤r≤N1 \leq l \leq r \leq N.

Here, mex(Al,⋯ ,Ar)\mathrm{mex}({A_l, \cdots, A_r}) denotes the smallest non-negative integer not contained in Al,⋯ ,ArA_l, \cdots, A_r.

给你一个长度为 NN 的非负整数序列 A=(A1,…,AN)A = (A_1, \dots, A_N)。

求所有满足 1≤l≤r≤N1 \leq l \leq r \leq N 的整数对 (l,r)(l, r) 对应的 mex(Al,⋯ ,Ar)\mathrm{mex}({A_l, \cdots, A_r}) 之和。

其中,mex(Al,⋯ ,Ar)\mathrm{mex}({A_l, \cdots, A_r}) 表示不在子序列 Al,⋯ ,ArA_l, \cdots, A_r 中出现的最小非负整数。

输入格式

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 ⋯\cdots ANA_N

输入从标准输入中按以下格式给出:

NN
A1A_1 A2A_2 ⋯\cdots ANA_N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    3
    1 2 0

    输出#1

    5
  • 输入#2

    6
    2 1 0 2 1 4

    输出#2

    31
  • 输入#3

    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

    输出#3

    624

说明/提示

Sample 1 Explanation:
The answer is 55, the sum of the following 66 values.

  • mex(A1)=mex(1)=0\mathrm{mex}({A_1}) = \mathrm{mex}({1}) = 0
  • mex(A1,A2)=mex(1,2)=0\mathrm{mex}({A_1,A_2}) = \mathrm{mex}({1,2}) = 0
  • mex(A1,A2,A3)=mex(1,2,0)=3\mathrm{mex}({A_1,A_2,A_3}) = \mathrm{mex}({1,2,0}) = 3
  • mex(A2)=mex(2)=0\mathrm{mex}({A_2}) = \mathrm{mex}({2}) = 0
  • mex(A2,A3)=mex(2,0)=1\mathrm{mex}({A_2,A_3}) = \mathrm{mex}({2,0}) = 1
  • mex(A3)=mex(0)=1\mathrm{mex}({A_3}) = \mathrm{mex}({0}) = 1

Sample 2 Explanation:
The answer is 3131, the sum of the following 2121 values.

  • mex(A1)=mex(2)=0\mathrm{mex}({A_1}) = \mathrm{mex}({2}) = 0
  • mex(A1,A2)=mex(2,1)=0\mathrm{mex}({A_1,A_2}) = \mathrm{mex}({2,1}) = 0
  • mex(A1,A2,A3)=mex(2,1,0)=3\mathrm{mex}({A_1,A_2,A_3}) = \mathrm{mex}({2,1,0}) = 3
  • mex(A1,A2,A3,A4)=mex(2,1,0,2)=3\mathrm{mex}({A_1,A_2,A_3,A_4}) = \mathrm{mex}({2,1,0,2}) = 3
  • mex(A1,A2,A3,A4,A5)=mex(2,1,0,2,1)=3\mathrm{mex}({A_1,A_2,A_3,A_4,A_5}) = \mathrm{mex}({2,1,0,2,1}) = 3
  • mex(A1,A2,A3,A4,A5,A6)=mex(2,1,0,2,1,4)=3\mathrm{mex}({A_1,A_2,A_3,A_4,A_5,A_6}) = \mathrm{mex}({2,1,0,2,1,4}) = 3
  • mex(A2)=mex(1)=0\mathrm{mex}({A_2}) = \mathrm{mex}({1}) = 0
  • mex(A2,A3)=mex(1,0)=2\mathrm{mex}({A_2,A_3}) = \mathrm{mex}({1,0}) = 2
  • mex(A2,A3,A4)=mex(1,0,2)=3\mathrm{mex}({A_2,A_3,A_4}) = \mathrm{mex}({1,0,2}) = 3
  • mex(A2,A3,A4,A5)=mex(1,0,2,1)=3\mathrm{mex}({A_2,A_3,A_4,A_5}) = \mathrm{mex}({1,0,2,1}) = 3
  • mex(A2,A3,A4,A5,A6)=mex(1,0,2,1,4)=3\mathrm{mex}({A_2,A_3,A_4,A_5,A_6}) = \mathrm{mex}({1,0,2,1,4}) = 3
  • mex(A3)=mex(0)=1\mathrm{mex}({A_3}) = \mathrm{mex}({0}) = 1
  • mex(A3,A4)=mex(0,2)=1\mathrm{mex}({A_3,A_4}) = \mathrm{mex}({0,2}) = 1
  • mex(A3,A4,A5)=mex(0,2,1)=3\mathrm{mex}({A_3,A_4,A_5}) = \mathrm{mex}({0,2,1}) = 3
  • mex(A3,A4,A5,A6)=mex(0,2,1,4)=3\mathrm{mex}({A_3,A_4,A_5,A_6}) = \mathrm{mex}({0,2,1,4}) = 3
  • mex(A4)=mex(2)=0\mathrm{mex}({A_4}) = \mathrm{mex}({2}) = 0
  • mex(A4,A5)=mex(2,1)=0\mathrm{mex}({A_4,A_5}) = \mathrm{mex}({2,1}) = 0
  • mex(A4,A5,A6)=mex(2,1,4)=0\mathrm{mex}({A_4,A_5,A_6}) = \mathrm{mex}({2,1,4}) = 0
  • mex(A5)=mex(1)=0\mathrm{mex}({A_5}) = \mathrm{mex}({1}) = 0
  • mex(A5,A6)=mex(1,4)=0\mathrm{mex}({A_5,A_6}) = \mathrm{mex}({1,4}) = 0
  • mex(A6)=mex(4)=0\mathrm{mex}({A_6}) = \mathrm{mex}({4}) = 0

Constraints

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 0≤Ai≤N0 \leq A_i \leq N
  • All input values are integers.

样例 1 解释:
答案为 55,是以下 66 个值的和。

  • mex(A1)=mex(1)=0\mathrm{mex}({A_1}) = \mathrm{mex}({1}) = 0
  • mex(A1,A2)=mex(1,2)=0\mathrm{mex}({A_1,A_2}) = \mathrm{mex}({1,2}) = 0
  • mex(A1,A2,A3)=mex(1,2,0)=3\mathrm{mex}({A_1,A_2,A_3}) = \mathrm{mex}({1,2,0}) = 3
  • mex(A2)=mex(2)=0\mathrm{mex}({A_2}) = \mathrm{mex}({2}) = 0
  • mex(A2,A3)=mex(2,0)=1\mathrm{mex}({A_2,A_3}) = \mathrm{mex}({2,0}) = 1
  • mex(A3)=mex(0)=1\mathrm{mex}({A_3}) = \mathrm{mex}({0}) = 1

样例 2 解释:
答案为 3131,是以下 2121 个值的和。

  • mex(A1)=mex(2)=0\mathrm{mex}({A_1}) = \mathrm{mex}({2}) = 0
  • mex(A1,A2)=mex(2,1)=0\mathrm{mex}({A_1,A_2}) = \mathrm{mex}({2,1}) = 0
  • mex(A1,A2,A3)=mex(2,1,0)=3\mathrm{mex}({A_1,A_2,A_3}) = \mathrm{mex}({2,1,0}) = 3
  • mex(A1,A2,A3,A4)=mex(2,1,0,2)=3\mathrm{mex}({A_1,A_2,A_3,A_4}) = \mathrm{mex}({2,1,0,2}) = 3
  • mex(A1,A2,A3,A4,A5)=mex(2,1,0,2,1)=3\mathrm{mex}({A_1,A_2,A_3,A_4,A_5}) = \mathrm{mex}({2,1,0,2,1}) = 3
  • mex(A1,A2,A3,A4,A5,A6)=mex(2,1,0,2,1,4)=3\mathrm{mex}({A_1,A_2,A_3,A_4,A_5,A_6}) = \mathrm{mex}({2,1,0,2,1,4}) = 3
  • mex(A2)=mex(1)=0\mathrm{mex}({A_2}) = \mathrm{mex}({1}) = 0
  • mex(A2,A3)=mex(1,0)=2\mathrm{mex}({A_2,A_3}) = \mathrm{mex}({1,0}) = 2
  • mex(A2,A3,A4)=mex(1,0,2)=3\mathrm{mex}({A_2,A_3,A_4}) = \mathrm{mex}({1,0,2}) = 3
  • mex(A2,A3,A4,A5)=mex(1,0,2,1)=3\mathrm{mex}({A_2,A_3,A_4,A_5}) = \mathrm{mex}({1,0,2,1}) = 3
  • mex(A2,A3,A4,A5,A6)=mex(1,0,2,1,4)=3\mathrm{mex}({A_2,A_3,A_4,A_5,A_6}) = \mathrm{mex}({1,0,2,1,4}) = 3
  • mex(A3)=mex(0)=1\mathrm{mex}({A_3}) = \mathrm{mex}({0}) = 1
  • mex(A3,A4)=mex(0,2)=1\mathrm{mex}({A_3,A_4}) = \mathrm{mex}({0,2}) = 1
  • mex(A3,A4,A5)=mex(0,2,1)=3\mathrm{mex}({A_3,A_4,A_5}) = \mathrm{mex}({0,2,1}) = 3
  • mex(A3,A4,A5,A6)=mex(0,2,1,4)=3\mathrm{mex}({A_3,A_4,A_5,A_6}) = \mathrm{mex}({0,2,1,4}) = 3
  • mex(A4)=mex(2)=0\mathrm{mex}({A_4}) = \mathrm{mex}({2}) = 0
  • mex(A4,A5)=mex(2,1)=0\mathrm{mex}({A_4,A_5}) = \mathrm{mex}({2,1}) = 0
  • mex(A4,A5,A6)=mex(2,1,4)=0\mathrm{mex}({A_4,A_5,A_6}) = \mathrm{mex}({2,1,4}) = 0
  • mex(A5)=mex(1)=0\mathrm{mex}({A_5}) = \mathrm{mex}({1}) = 0
  • mex(A5,A6)=mex(1,4)=0\mathrm{mex}({A_5,A_6}) = \mathrm{mex}({1,4}) = 0
  • mex(A6)=mex(4)=0\mathrm{mex}({A_6}) = \mathrm{mex}({4}) = 0

约束条件

  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 0≤Ai≤N0 \leq A_i \leq N
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页