CF961E.Tufurama

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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 a__i episodes (numbered 1 through a__i). 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!

一天,Polycarp 决定重看自己最爱的知名电视剧《Tufurama》的某一集。当他用搜索词“在线高清免费观看 Tufurama 第 3 季第 7 集”进行搜索时,却只得到了第 7 季第 3 集的结果。这令 Polycarp 十分惊讶——万一将来某天他想把整部剧从头到尾重看一遍,却找不到正确的集数该怎么办?现在 Polycarp 想统计一下,将来他将被迫使用其他方法搜索剧集的次数。

该电视剧共有 nn 季(编号为 11 到 nn),其中第 ii 季有 aia_i 集(编号为 11 到 aia_i)。Polycarp 认为:若存在一对整数 xx 和 yy(满足 x<yx < y),使得第 xx 季第 yy 集与第 yy 季第 xx 集均真实存在,则其中至少一个搜索查询会返回错误结果。请帮助 Polycarp 计算满足该条件的 (x,y)(x, y) 对的数量!

输入格式

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

The second line contains n integers separated by space _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) — number of episodes in each season.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 季数。

第二行包含 nn 个用空格分隔的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)—— 每季的集数。

输出格式

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.

输出一个整数——满足条件的数对 xx 和 yy(其中 x<yx < y)的个数,使得同时存在第 xx 季第 yy 集和第 yy 季第 xx 集。

输入输出样例

  • 输入#1

    5
    1 2 3 4 5

    输出#1

    0
  • 输入#2

    3
    8 12 7

    输出#2

    3
  • 输入#3

    3
    3 2 1

    输出#3

    2

说明/提示

Possible pairs in the second example:

  1. x = 1, y = 2 (season 1 episode 2 season 2 episode 1);
  2. x = 2, y = 3 (season 2 episode 3 season 3 episode 2);
  3. x = 1, y = 3 (season 1 episode 3 season 3 episode 1).

In the third example:

  1. x = 1, y = 2 (season 1 episode 2 season 2 episode 1);
  2. x = 1, y = 3 (season 1 episode 3 season 3 episode 1).

第二个样例中的可能配对:

  1. x=1x = 1,y=2y = 2(第 1 季第 2 集 第 2 季第 1 集);
  2. x=2x = 2,y=3y = 3(第 2 季第 3 集 第 3 季第 2 集);
  3. x=1x = 1,y=3y = 3(第 1 季第 3 集 第 3 季第 1 集)。

第三个样例中:

  1. x=1x = 1,y=2y = 2(第 1 季第 2 集 第 2 季第 1 集);
  2. x=1x = 1,y=3y = 3(第 1 季第 3 集 第 3 季第 1 集)。

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

首页