Codeforces Round #495 C. Sonya and Robots
题意
给你n个数字,让你从这个序列中选一对数(a,b),使得从左边数第一个a出现的位置 < 从右边数第一个b出现的位置,问符合要求的对数有多少个?
思路
仔细想一下,如果给你的n个数字中,每一个数字都是不同的,那么我们的答案其实就是,n-1,n-2,n-3….1对吧,如果这几个数字中有重复的那么我们就没有办法这样弄,怎么办呢?对于一种数来说,可以满足条件的是你出现的后面的数,比如说你后面有x种数,那么就可以凑成x种序列,之后每一种数出现一次我们就让他减1,如果说减到0了就说明这种数已经没有了,我们让x– 就ok了
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int vis2[maxn];
map<int,int>M;
int main()
{int n;scanf("%d",&n);for(int i = 0 ;i < n ; i++){scanf("%d",&a[i]);M[a[i]]++;} int x = M.size();long long ans = 0;for(int i = 0 ; i < n ; i++){if(--M[a[i]] == 0){x--;}if(!vis2[a[i]]){ans += x;vis2[a[i]] = 1;}}cout<<ans<<endl;
}
/*
5
1 5 4 1 3
*/
Codeforces Round #495 C. Sonya and Robots相关推荐
- Codeforces Round #495 (Div. 2) D. Sonya and Matrix[思维构造]
D. Sonya and Matrix 题意:给定t个数,要求构造一个矩阵,以0为中心,以菱形的方法依次+1扩展 思路: 假设0的坐标为(x,y),则有 max=n-x+m-y max已知, n,m枚 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)
Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- Codeforces Round #270
Codeforces Round #270 题目链接 A:我是筛了下素数.事实上偶数仅仅要输出4和x - 4,奇数输出9和x - 9就可以 B:贪心的策略,把时间排序后.取每k个的位置 C:贪心.每次 ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
最新文章
- Pytho正则表达式-match
- python中回车怎么表示_如何在python中使用读取行仅拆分回车符?
- linux用命令连接wifi密码,Linux下如何通过命令连接wifi
- linux mysql 定时任务_Linux下Mysql定时任务备份数据的实现方法
- 步骤mysql_mysql 安装 等步骤(一)
- 奇异值分解与低秩矩阵近似
- linux档案内容怎么写,Linux cat输出档案命令详解
- Navicat注册机报错No all pattern found! file already patched
- 用ADB操纵手机实现连点器(折衷案)
- 运用getParameterNames()方法和getParameterValues()方法获取请求参数名称和内容
- 《Chrysanthemums Terrace》《菊花台》
- ORACLE 常用的SQL语法和数据对象
- 谨赠20篇技术热文营造一个不一样的节日气氛!
- 推荐8个免费好用的网站
- nexus 向私服推送jar包 两种方式实现
- 服务器-epoll之缓冲区
- 架设个人FTP——ServU
- SQL Server profile使用技巧
- html中奇数偶数判断,js中判断奇数或偶数
- 地胶地板施工工艺,地板胶怎么去掉