Sonya and Robots
1 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std; int a[];
int rd[]; int main()
{
set<int>s;
int n;
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",&a[i]); for(int i=n;i>=;i--)
{
s.insert(a[i]);
rd[i]=s.size(); //预处理:记录 下标大于等于i并且不重复的a[i]的'数目'
}
s.clear(); long long sum=; //int会爆
for(int i=;i<=n;i++)
{
if(s.find(a[i]) == s.end() ) //如果还没有出现过a[i];
{
s.insert(a[i]); //那就加入a[i];
sum+= rd[i+]; //加上 下标在i之后(不包括i)的不重复的a[i] 数量
} //最后一个 rd[n+1]=0 默认等于0
}
cout<<sum<<endl;
} http://codeforces.com/group/1EzrFFyOc0/contest/1004/problem/C
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std; const int maxn=1e5+;
int a[maxn];
int rd[maxn];
bool vis[maxn]; int main()
{
int n;
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",&a[i]); for(int i=n;i>=;i--)
{
rd[i]=rd[i+]; //继承
if( !vis[a[i]] )
{
vis[a[i]]=;
rd[i]++;
}
}
memset(vis,,sizeof(vis));
ll sum=;
for(int i=;i<=n;i++)
{
if( !vis[a[i]] )
{
sum += rd[i+];
vis[a[i]]=;
}
}
cout<<sum<<endl;
}
Sonya and Robots的更多相关文章
- codeforces ~ 1004 C Sonya and Robots (dp)
C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Sonya and Robots CodeForces - 1004C (思维题)
Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input: standard in ...
- Sonya and Robots(CodeForces 1004C)
Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...
- Codeforces Round #495 (Div. 2) C. Sonya and Robots
http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...
- 网站 robots.txt 文件编写
网站 robots.txt 文件编写 Intro robots.txt 是网站根目录下的一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的 ...
- Robots.txt - 禁止爬虫(转)
Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...
- (转载)robots.txt写法大全和robots.txt语法的作用
1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...
- Codeforces713C Sonya and Problem Wihtout a Legend(DP)
题目 Source http://codeforces.com/problemset/problem/713/C Description Sonya was unable to think of a ...
- 2016 ccpc 网络选拔赛 F. Robots
Robots Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
随机推荐
- React16+配置打包目录
在学习react的时候,肯定最终都要用脚手架,对比了手写配置webpack(比较费劲).generator-react-webpack(打不开官方文档……),最终还是选择了react官方的create ...
- API网关从入门到放弃
前言 假设你正在开发一个电商网站,那么这里会涉及到很多后端的微服务,比如会员.商品.推荐服务等等. 那么这里就会遇到一个问题,APP/Browser怎么去访问这些后端的服务? 如果业务比较简单的话,可 ...
- 阿里云ECS服务器活动99元一年(2019年 Hi拼团,拼着买,更划算)
2019年10月22日更新,阿里云推荐有礼活动:ECS突发性能T6-低至99元/年赶紧上车~ 低价高性能,拼着买更划算 点我参加活动>> 购买前领取阿里云幸运券,更有可能享受折上折的优惠. ...
- 【数据库开发】 C连接mysql——常用的函数
转载:http://blog.chinaunix.net/uid-26758020-id-3288633.html 1.MYSQL *mysql_init(MYSQL *mysql) 为mysq ...
- 乐字节Java反射之二:实例化对象、接口与父类、修饰符和属性
大家好,小乐继续接着上集:乐字节Java反射之一:反射概念与获取反射源头Class 这次是之二:实例化对象.接口与父类.修饰符和属性 一:实例化对象 之前我们讲解过创建对象的方式,有new .克隆.反 ...
- K8S踩坑篇-master节点作为node节点加入集群
前面我们二进制部署K8S集群时,三台master节点仅仅作为集群管理节点,所以master节点上中并未部署docker.kubelet.kube-proxy等服务.后来我在部署mertics-serv ...
- javaIO -- InputStream和OutStream
一.简介 InputStream 和 OutputStream 对于字节流的输入和输出是作为协议的存在 所以有必要了解下这两个类提供出来的基本约定,这两个类是抽象类,而且基本上没什么实现,都是依赖于子 ...
- Feign【@FeignClient】
首先看一下@FeignClient注解的源码: package org.springframework.cloud.openfeign; import java.lang.annotation.Doc ...
- PAT甲级 进制转换题_C++题解
进制转换题 PAT (Advanced Level) Practice 进制转换题 目录 <算法笔记> 重点摘要 1015 Reversible Primes (20) 1019 Gene ...
- linux下查看当前进程以及杀死进程
###linux下查看当前进程以及杀死进程 查看进程 ps命令查找与进程相关的PID号: ps a :显示现行终端机下的所有程序,包括其他用户的程序. ps -A :显示所有程序. ps c :列出程 ...