QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8634. 求和

統計

题目描述

给定一个包含 $\{0,...,n-1\}$ 中每个数恰好一次的序列 $\{a_i\}$,求:

$$ \sum_{l=1}^n\sum_{r=l}^n mex(\{a_l,...,a_r\}) $$

其中,$mex(S)=min\{i\in \mathbb{N}|i\notin S\}$。注意:在本题里, $0\in \mathbb{N}$。

输入格式

从标准输入读入数据。

输入共两行。

第一行包含一个正整数 $n$。

第二行是 $n$ 个以空格隔开的非负整数,保证这 $n$ 个数是 $\{0,...,n-1\}$ 的一个排列。

输出格式

输出到标准输出。

输出一个整数,表示题目中所描述式子的答案。

样例

输入

5
4 3 1 2 0

输出

14

样例

输入

10
7 2 6 5 3 9 8 4 0 1

输出

40

解释

数据范围

对于 $10\%$ 的数据保证:$n\le100$。

对于 $30\%$ 的数据保证:$n\le300$。

对于 $50\%$ 的数据保证:$n\le 5000$。

对于所有测试数据保证:$1\le n\le 10^6$,输入的 $n$ 个数是 $\{0,...,n-1\}$ 的一个排列。

提示

请注意答案的范围!

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.