A891 | Why Did the Cow Cross the Road III--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
The layout of Farmer John's farm is quite peculiar, with a large circular road
running around the perimeter of the main field on which his cows graze during
the day. Every morning, the cows cross this road on their way towards the
field, and every evening they all cross again as they leave the field and
return to the barn.
As we know, cows are creatures of habit, and they each cross the road the same
way every day. Each cow crosses into the field at a different point from where
she crosses out of the field, and all of these crossing points are distinct
from each-other. Farmer John owns $N$ cows, conveniently identified with the
integer IDs $1 \ldots N$, so there are precisely $2N$ crossing points around
the road. Farmer John records these crossing points concisely by scanning
around the circle clockwise, writing down the ID of the cow for each crossing
point, ultimately forming a sequence with $2N$ numbers in which each number
appears exactly twice. He does not record which crossing points are entry
points and which are exit points.
Looking at his map of crossing points, Farmer John is curious how many times
various pairs of cows might cross paths during the day. He calls a pair of
cows $(a,b)$ a "crossing" pair if cow $a$'s path from entry to exit must cross
cow $b$'s path from entry to exit. Please help Farmer John count the total
number of crossing pairs.
running around the perimeter of the main field on which his cows graze during
the day. Every morning, the cows cross this road on their way towards the
field, and every evening they all cross again as they leave the field and
return to the barn.
As we know, cows are creatures of habit, and they each cross the road the same
way every day. Each cow crosses into the field at a different point from where
she crosses out of the field, and all of these crossing points are distinct
from each-other. Farmer John owns $N$ cows, conveniently identified with the
integer IDs $1 \ldots N$, so there are precisely $2N$ crossing points around
the road. Farmer John records these crossing points concisely by scanning
around the circle clockwise, writing down the ID of the cow for each crossing
point, ultimately forming a sequence with $2N$ numbers in which each number
appears exactly twice. He does not record which crossing points are entry
points and which are exit points.
Looking at his map of crossing points, Farmer John is curious how many times
various pairs of cows might cross paths during the day. He calls a pair of
cows $(a,b)$ a "crossing" pair if cow $a$'s path from entry to exit must cross
cow $b$'s path from entry to exit. Please help Farmer John count the total
number of crossing pairs.
输入格式
The first line of input contains $N$ ($1 \leq N \leq 50,000$), and the next
$2N$ lines describe the cow IDs for the sequence of entry and exit points
around the field.
$2N$ lines describe the cow IDs for the sequence of entry and exit points
around the field.
输出格式
Please print the total number of crossing pairs.
输入输出样例
输入 #1
4 3 2 4 4 1 3 2 1
输出 #1
3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted