标签:contains dex 16px strong this pretty ide using search
挺巧妙的数据结构题(不过据说这是一种套路?
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!
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.
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 就
标签:contains dex 16px strong this pretty ide using search
原文地址:https://www.cnblogs.com/antiquality/p/8746718.html