码迷,mamicode.com
首页 > 其他好文 > 详细

CF961E Tufurama

时间:2018-04-08 19:43:42      阅读:435      评论:0      收藏:0      [点我收藏+]

标签:contains   dex   16px   strong   this   pretty   ide   using   search   

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

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

标签:contains   dex   16px   strong   this   pretty   ide   using   search   

原文地址:https://www.cnblogs.com/antiquality/p/8746718.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!