A10299 | Foe Pairs
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n$ and $m$ ( $1<=n,m<=3·10^{5}$ ) — 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.
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.
输出格式
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.
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.
输入输出样例
输入 #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)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted