A11950 | Sonya and Robots
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$ -th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$ -st position while the second one in the $3$ -rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$ -rd position while the second one is in the $2$ -nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ( $p$ , $q$ ), where she will give $p$ to the first robot and $q$ to the second one. Pairs ( $p_i$ , $q_i$ ) and ( $p_j$ , $q_j$ ) are different if $p_i\neq p_j$ or $q_i\neq q_j$ .
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$ -th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.
Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.
For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$ -st position while the second one in the $3$ -rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$ -rd position while the second one is in the $2$ -nd position.
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.
Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ( $p$ , $q$ ), where she will give $p$ to the first robot and $q$ to the second one. Pairs ( $p_i$ , $q_i$ ) and ( $p_j$ , $q_j$ ) are different if $p_i\neq p_j$ or $q_i\neq q_j$ .
Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
输入格式
The first line contains a single integer $n$ ( $1\leq n\leq 10^5$ ) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1\leq a_i\leq 10^5$ ) — the numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1\leq a_i\leq 10^5$ ) — the numbers in a row.
输出格式
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
输入输出样例
输入 #1
5 1 5 4 1 3
输出 #1
9
输入 #2
7 1 2 1 1 1 3 2
输出 #2
7
In the first example, Sonya can give pairs ( $1$ , $1$ ), ( $1$ , $3$ ), ( $1$ , $4$ ), ( $1$ , $5$ ), ( $4$ , $1$ ), ( $4$ , $3$ ), ( $5$ , $1$ ), ( $5$ , $3$ ), and ( $5$ , $4$ ).
In the second example, Sonya can give pairs ( $1$ , $1$ ), ( $1$ , $2$ ), ( $1$ , $3$ ), ( $2$ , $1$ ), ( $2$ , $2$ ), ( $2$ , $3$ ), and ( $3$ , $2$ ).
In the second example, Sonya can give pairs ( $1$ , $1$ ), ( $1$ , $2$ ), ( $1$ , $3$ ), ( $2$ , $1$ ), ( $2$ , $2$ ), ( $2$ , $3$ ), and ( $3$ , $2$ ).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted