CF652C.Foe Pairs
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation p of length n. Also you are given m foe pairs (a__i, b__i) (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i).
Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).
Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.
给你一个长度为 n 的排列 p。同时,你还会得到 m 个“敌对对” (ai,bi)(其中 1≤ai,bi≤n,且 ai=bi)。
你的任务是统计满足如下条件的区间 (x,y)(其中 1≤x≤y≤n)的个数:该区间不包含任何敌对对。换言之,你不应统计那些至少包含一个敌对对的区间 (x,y)(敌对对中两个值在区间内的位置和相对顺序无关)。
考虑如下示例:p=[1,3,2,4],敌对对为 {(3,2),(4,2)}。区间 (1,3) 是不合法的,因为它包含了敌对对 (3,2);区间 (1,4) 同样不合法,因为它包含了两个敌对对 (3,2) 和 (4,2);但区间 (1,2) 是合法的,因为它不包含任何敌对对。
输入格式
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the length of the permutation p and the number of foe pairs.
The second line contains n distinct integers p__i (1 ≤ p__i ≤ n) — the elements of the permutation p.
Each of the next m lines contains two integers (a__i, b__i) (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.
第一行包含两个整数 n 和 m(1≤n,m≤3⋅105)—— 分别表示排列 p 的长度以及敌对对的数量。
第二行包含 n 个互不相同的整数 pi(1≤pi≤n)—— 表示排列 p 的元素。
接下来的 m 行中,每行包含两个整数 (ai,bi)(1≤ai,bi≤n,且 ai=bi)—— 表示第 i 个敌对对。注意:给定列表中可能出现重复的敌对对。
输出格式
Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
输出唯一的整数 c —— 即不包含任何敌对数对的区间 (x,y) 的个数。
注意:答案可能非常大,因此应使用 64 位整数类型来存储。在 C++ 中可使用 long long 类型,在 Java 中可使用 long 类型。
输入输出样例
输入#1
4 2 1 3 2 4 3 2 2 4
输出#1
5
输入#2
9 5 9 7 2 3 1 4 6 5 8 1 6 4 5 2 7 7 2 2 7
输出#2
20
说明/提示
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
在第一个例子中,答案中的区间为 (1,1)、(1,2)、(2,2)、(3,3) 和 (4,4)。
输入解题思路,AI测评打分。不知道怎么写?