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 ...
随机推荐
- 生成count位随机数工具类
工具类 import java.util.Random; /** * 生成6位随机数字 */ public class GeneratorCode { /** * * @Title: getCode ...
- Flutter状态管理Provider,简单上手
在之前的文章中介绍了 Google 官方仓库下的一个状态管理 Provide.乍一看这俩玩意可能很容易就被认为是同一个东西,仔细一看,这不就差了一个字吗,有什么区别呢. 首先,你要知道的最大的一个区别 ...
- Python sys.path永久添加
在用户目录下,找到隐藏文件.bashrc 或 .zshrc 文件然后在末尾添加 export PYTHONPATH=$PYTHONPATH:/home/dev/custom_path 操作:vim . ...
- 到处抄来的SUCTF2019 web wp
0x01 EasySQL 这是一个考察堆叠注入的题目,但是这道题因为作者的过滤不够完全所以存在非预期解 非预期解 直接构造 *,1 这样构造,最后拼接的查询语句就变成了 select *,1||fla ...
- windows下进程与线程
windows下进程与线程 Windows是一个单用户多任务的操作系统,同一时间可有多个进程在执行.进程是应用程序的运行实例,可以理解为应用程序的一次动态执行:而线程是CPU调度的单位,是进程的一个执 ...
- C#使用KingAOP实现AOP面向切面编程二
本文继续上篇讲述一下比较复杂点的AOP例子,先新建一个控制台项目,然后同样先在Nuget中搜索安装KingAop到项目中 1.项目结构 2 .定义一个登录实体类User和LoggingAspect切面 ...
- layui监听复选按钮点击
layui.form.on('checkbox(resultQuery)', function(data){ console.log(data.elem); //得到checkbox原始DOM对象 c ...
- php open_basedir的使用与性能分析
php open_basedir的使用与性能分析 使用方法 <pre>/*限制打开的目录*/ini_set('open_basedir', __DIR__.'/');</pre> ...
- windwos提权-CVE-2019-1388
windwos提权-CVE-2019-1388 guest→system(UAC手动提权) 利用高权限建立一个低权限账户orange 查看权限 win-vomjm1p7c71\orange 下载HHU ...
- Servlet 响应及请求信息
// 文件路径 D:\ApacheServer\web_java\HelloWorld\src\com\test\TestServletRequestrResponse.java package co ...