102622: [AtCoder]ABC262 C - Min Max Pair
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $300$ points
Problem Statement
You are given a sequence $a = (a_1, \dots, a_N)$ of length $N$ consisting of integers between $1$ and $N$.
Find the number of pairs of integers $i, j$ that satisfy all of the following conditions:
- $1 \leq i \lt j \leq N$
- $\min(a_i, a_j) = i$
- $\max(a_i, a_j) = j$
Constraints
- $2 \leq N \leq 5 \times 10^5$
- $1 \leq a_i \leq N \, (1 \leq i \leq N)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $a_1$ $\ldots$ $a_N$
Output
Print the answer.
Sample Input 1
4 1 3 2 4
Sample Output 1
2
$(i, j) = (1, 4), (2, 3)$ satisfy the conditions.
Sample Input 2
10 5 8 2 2 1 6 7 2 9 10
Sample Output 2
8
Input
题意翻译
给定一个包含 $N$ 个正整数的序列 $a$ 。求出所有满足条件的 $(i,j)$ 的数量: - $ 1\ \leq\ i\ \lt\ j\ \leq\ N $ - $ \min(a_i,\ a_j)\ =\ i $ - $ \max(a_i,\ a_j)\ =\ j $Output
分数:$300$分
问题描述
你被给定一个长度为$N$的序列$a = (a_1, \dots, a_N)$,其中包含$1$到$N$之间的整数。
找出满足以下所有条件的整数对$i, j$的数量:
- $1 \leq i \lt j \leq N$
- $\min(a_i, a_j) = i$
- $\max(a_i, a_j) = j$
约束条件
- $2 \leq N \leq 5 \times 10^5$
- $1 \leq a_i \leq N \, (1 \leq i \leq N)$
- 输入中的所有值都是整数。
输入
从标准输入按照以下格式获取输入:
$N$ $a_1$ $\ldots$ $a_N$
输出
打印答案。
样例输入1
4 1 3 2 4
样例输出1
2
$(i, j) = (1, 4), (2, 3)$满足条件。
样例输入2
10 5 8 2 2 1 6 7 2 9 10
样例输出2
8