CF961E Tufurama

Posted AntiQuality

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF961E Tufurama相关的知识,希望对你有一定的参考价值。

挺巧妙的数据结构题(不过据说这是一种套路?

E. Tufurama

One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the entire series someday and won‘t be able to find the right episodes to watch? Polycarp now wants to count the number of times he will be forced to search for an episode using some different method.

TV series have n seasons (numbered 1 through n), the i-th season has ai episodes (numbered 1 through ai). Polycarp thinks that if for some pair of integers x and y (x < y) exist both season x episode y and season y episode x then one of these search queries will include the wrong results. Help Polycarp to calculate the number of such pairs!

Input

The first line contains one integer n (1  ≤ n  ≤  2·10^5) — the number of seasons.

The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 10^9) — number of episodes in each season.

Output

Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.


题目大意

有一部电视剧有n季,每一季有ai集。定义二元组(i,j):存在第i季有第j集。求(i,j)与(j,i)合法(i<j)的对数。


 

看上去很可做的样子,对吧……

题目分析

基础的暴力

从1..n季,每一季都分别判断对答案的贡献。

例如对于 4 3 5 1 2 就

 

以上是关于CF961E Tufurama的主要内容,如果未能解决你的问题,请参考以下文章

CF961E Tufurama

CF961E Tufurama

CF961E Tufurama 主席树

Educational Codeforces Round 41 E. Tufurama (961E)

CF - 主席树 E

主席树补充练习