第六次个人赛

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn nn numbers in a row, aiai is located in the ii-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][1,5,4,1,3] are written, and Sonya gives the number 11 to the first robot and the number 44 to the second one, the first robot will stop in the 11-st position while the second one in the 33-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 44 to the first robot and the number 55 to the second one, they will meet since the first robot will stop in the 33-rd position while the second one is in the 22-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 (pp, qq), where she will give pp to the first robot and qq to the second one. Pairs (pipi, qiqi) and (pjpj, qjqj) are different if pi≠pjpi≠pj or qi≠qjqi≠qj.

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.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of numbers in a row.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105) — the numbers in a row.

Output

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.

Sample Input

Input

5
1 5 4 1 3

Output

9

Input

7
1 2 1 1 1 3 2

Output

7

Hint

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).

题意:

给你n个数字,让你求出他们有多少组合对,不能重复

思路:

set求出在每个数字之前有多少不重复的数字,就能组成多少数对,采用逆序的思路

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>typedef long long LL;
const long long INF = 0x3f3f3f3f;
const long long mod = 1e9+7;
const double PI = acos(-1.0);
const int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir8[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
const int N = 100010;
using namespace std;
set<int> st;
int a[N],vis[N];
int main()
{int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];vis[a[i]]=st.size();st.insert(a[i]);}LL ans=0;for(int i=0;i<=100000;i++){ans+=vis[i];}cout<<ans<<endl;return 0;
}

Sonya and Robots(set应用)相关推荐

  1. Codeforces Round #495 C. Sonya and Robots

    题意 给你n个数字,让你从这个序列中选一对数(a,b),使得从左边数第一个a出现的位置 < 从右边数第一个b出现的位置,问符合要求的对数有多少个? 思路 仔细想一下,如果给你的n个数字中,每一个 ...

  2. cf Sonya and Robots

    题目网址点击打开链接 题目意思是给你一个序列,要从左边数起第一个a的位置要在从右边数起第一个b的位置的前面,让你求(a,b)这样的一对数的种数是多少. 序列里的每个数都可以和他后面的全部数组成(a,b ...

  3. 常用技巧 —— 桶排

    [概述] 桶排的思想是一种比较重要的技巧,在 由于桶排的特殊性,桶排仍需进行模拟装桶的过程,而且有时由于数据范围无法开很大的数组,需要使用 map 与其结合 关于桶排:点击这里 [例题] Romaji ...

  4. HDU 6229 Wandering Robots 找规律+离散化

    题目链接:Wandering Robots 题解:先讲一下规律,对于每一个格子它可以从多少个地方来有一个值(可以从自己到自己),然后答案就是统计合法格子上的数与所有格子的数的比值 比如说样例的3 0格 ...

  5. 如何写网站的robots.txt和meta name robots的配置

    robots.txt基本介绍robots.txt是一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的内容. 当一个搜索机器人(有的叫搜索蜘 ...

  6. robots.txt文件的解析及过滤

    什么是robots.txt文件? robots.txt(统一小写)是一种存放于网站根目录下的ASCII编码的文本文件,它通常告诉网络搜索引擎的漫游器(又称网络蜘蛛),此网站中的哪些内容是不能被搜索引擎 ...

  7. Python爬虫小偏方:如何用robots.txt快速抓取网站?

    作者 | 王平,一个IT老码农,写Python十年有余,喜欢分享通过爬虫技术挣钱和Python开发经验. 来源 | 猿人学Python 在我抓取网站遇到瓶颈,想剑走偏锋去解决时,常常会先去看下该网站的 ...

  8. HDU 2300 Crashing Robots

    Crashing Robots 题意 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态 这是个模拟题需要注意几点: 理解转变方向后移动多少米,和转动方 ...

  9. 【谷歌推网页爬虫新标准,开源robots.txt解析器】

    https://www.toutiao.com/a1638031116246019 [谷歌推网页爬虫新标准,开源robots.txt解析器] 对于接触过网络爬虫的人来说 robots.txt 绝不陌生 ...

  10. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 1 /* 2 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出 ...

最新文章

  1. Oracle数据库对象,同义词、序列、视图、索引
  2. Android NDK 使用自己的共享库(Import Module)
  3. IBM GSA Senior DBA招聘
  4. 将Bitmap byte裸数据转换成Bitmap图片int数据
  5. 从零入门 FreeRTOS 操作系统之任务调度器
  6. 温州大学《深度学习》课程课件(六、优化算法)
  7. eclipse+pydev快捷键
  8. Add a All Document Folder
  9. 远程对象工厂设计模式
  10. Informatica使用pmrep备份存储库
  11. python经典编程100例(1)
  12. 怎么测量标准工时,实用分享:几种标准工时的测量方法
  13. 《分布式资本链周刊》第二期
  14. Windows动态链接库DLL和静态库的原理以及创建方法
  15. android 微信搜索功能,[多图]等了N年的功能来了 Android微信8.0.3新版体验
  16. 如何解决取ADO的Recordset对象的RecordCount属性总是-1问题
  17. 真空密码字典生成器分享
  18. cs61c笔记-Lecture6 floating points浮点数
  19. python读parquet文件 pandas读parquet文件
  20. APNG面向移动与未来的新动画图片格式揭秘与制作全技巧

热门文章

  1. k8s api文档 调用heapster metrics
  2. 微信公众号用到的网站
  3. 使用Cargo入门rust语言
  4. View相关知识学习总结
  5. 如何学习angular.js
  6. 自动化部署关于在ubuntu下的docker容器折腾小记
  7. squid内存监控脚本
  8. SqlServer修改密码后登陆不上
  9. 近乎 5.3 发布,SNS 社区系统
  10. 同步异步阻塞非阻塞杂记 1