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 ...
随机推荐
- yarn和npm
Yarn和npm命令对比 npm install === yarn npm install taco --save === yarn add taco npm uninstall taco --sav ...
- 遇到引入的JS不起作用
1.js的加载是有先后顺序的,并且不能重复引入,重复引入的只有最后一个起作用 2.在使用ligerUI的时候一定要先引用jQuery再引用ligerUI 3.在使用jQuery时遇到变量名未定义的主要 ...
- 用BERT做语义相似度匹配任务:计算相似度的方式
1. 自然地使用[CLS] 2. cosine similairity 3. 长短文本的区别 4. sentence/word embedding 5. siamese network 方式 1. 自 ...
- 冲刺Noip2017模拟赛8 解题报告——五十岚芒果酱
1.鼎纹 [问题描述] 据说鼎纹的 种制造 式是 铜模印出来的,这是我国古代劳动 智慧 的结晶.铜模印过的地 ,会留下深深的印记,经过时间的炼化,洗 练成历史的遗存. 聪明的古代劳动人民拥有一个 a ...
- Postman 下载和使用
Postman 的官网下载地址是:https://www.getpostman.com/apps/
- 【leetcode算法-简单】28. 实现strStr
[题目描述] 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如 ...
- Hive 数据类型及操作数据库
3. Hive 数据类型 3.1 基本数据类型 Hive 数据类型 Java 数据类型 长度 TINYINT byte 1 byte 有符号整数 SMALINT short 2 byte 有符号整数 ...
- java - redis学习
在学习redis之前,我们首先需要了解一下NoSQL(非关系数据库).非关系型数据库通常指数据以对象的形式存储在数据库中,而对象之间的关系通过每个对象自身的属性来决定. 为什么需要NoSQL? (1) ...
- Qt程序开机自动运行
一.写入注册表需要管理员权限 1.开发中生成并运行程序需要写入注册表时,应该以管理员权限打开项目: 2.点击程序运行需要写入注册表,则应该以管理员权限打开此程序. 二.实现 void MoreSetW ...
- PHP之即点即改
html: <td data-hide="1200" class="px12" id ="<?php echo $v['g_id'];?& ...