1.  
  2. 1 #include<iostream>
  3. #include<cstdio>
  4. #include<algorithm>
  5. #include<cstring>
  6. #include<set>
  7. using namespace std;
  8.  
  9. int a[];
  10. int rd[];
  11.  
  12. int main()
  13. {
  14. set<int>s;
  15. int n;
  16. cin>>n;
  17. for(int i=;i<=n;i++)
  18. scanf("%d",&a[i]);
  19.  
  20. for(int i=n;i>=;i--)
  21. {
  22. s.insert(a[i]);
  23. rd[i]=s.size(); //预处理:记录 下标大于等于i并且不重复的a[i]的'数目'
  24. }
  25. s.clear();
  26.  
  27. long long sum=; //int会爆
  28. for(int i=;i<=n;i++)
  29. {
  30. if(s.find(a[i]) == s.end() ) //如果还没有出现过a[i];
  31. {
  32. s.insert(a[i]); //那就加入a[i];
  33. sum+= rd[i+]; //加上 下标在i之后(不包括i)的不重复的a[i] 数量
  34. } //最后一个 rd[n+1]=0 默认等于0
  35. }
  36. cout<<sum<<endl;
  37. }
  38.  
  39. http://codeforces.com/group/1EzrFFyOc0/contest/1004/problem/C
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #define ll long long
  6. using namespace std;
  7.  
  8. const int maxn=1e5+;
  9. int a[maxn];
  10. int rd[maxn];
  11. bool vis[maxn];
  12.  
  13. int main()
  14. {
  15. int n;
  16. cin>>n;
  17. for(int i=;i<=n;i++)
  18. scanf("%d",&a[i]);
  19.  
  20. for(int i=n;i>=;i--)
  21. {
  22. rd[i]=rd[i+]; //继承
  23. if( !vis[a[i]] )
  24. {
  25. vis[a[i]]=;
  26. rd[i]++;
  27. }
  28. }
  29. memset(vis,,sizeof(vis));
  30. ll sum=;
  31. for(int i=;i<=n;i++)
  32. {
  33. if( !vis[a[i]] )
  34. {
  35. sum += rd[i+];
  36. vis[a[i]]=;
  37. }
  38. }
  39. cout<<sum<<endl;
  40. }
  1.  
  1.  

Sonya and Robots的更多相关文章

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

  2. Sonya and Robots CodeForces - 1004C (思维题)

    Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input: standard in ...

  3. Sonya and Robots(CodeForces 1004C)

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

  4. Codeforces Round #495 (Div. 2) C. Sonya and Robots

    http://codeforces.com/contest/1004/problem/C 题意: 在一行上有n个数字,现在在最左边和最右边各放置一个机器人,左右机器人各有一个数字p和q.现在这两个机器 ...

  5. 网站 robots.txt 文件编写

    网站 robots.txt 文件编写 Intro robots.txt 是网站根目录下的一个纯文本文件,在这个文件中网站管理者可以声明该网站中不想被robots访问的部分,或者指定搜索引擎只收录指定的 ...

  6. Robots.txt - 禁止爬虫(转)

    Robots.txt - 禁止爬虫 robots.txt用于禁止网络爬虫访问网站指定目录.robots.txt的格式采用面向行的语法:空行.注释行(以#打头).规则行.规则行的格式为:Field: v ...

  7. (转载)robots.txt写法大全和robots.txt语法的作用

    1如果允许所有搜索引擎访问网站的所有部分的话 我们可以建立一个空白的文本文档,命名为robots.txt放在网站的根目录下即可.robots.txt写法如下:User-agent: *Disallow ...

  8. Codeforces713C Sonya and Problem Wihtout a Legend(DP)

    题目 Source http://codeforces.com/problemset/problem/713/C Description Sonya was unable to think of a ...

  9. 2016 ccpc 网络选拔赛 F. Robots

    Robots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

随机推荐

  1. yarn和npm

    Yarn和npm命令对比 npm install === yarn npm install taco --save === yarn add taco npm uninstall taco --sav ...

  2. 遇到引入的JS不起作用

    1.js的加载是有先后顺序的,并且不能重复引入,重复引入的只有最后一个起作用 2.在使用ligerUI的时候一定要先引用jQuery再引用ligerUI 3.在使用jQuery时遇到变量名未定义的主要 ...

  3. 用BERT做语义相似度匹配任务:计算相似度的方式

    1. 自然地使用[CLS] 2. cosine similairity 3. 长短文本的区别 4. sentence/word embedding 5. siamese network 方式 1. 自 ...

  4. 冲刺Noip2017模拟赛8 解题报告——五十岚芒果酱

    1.鼎纹 [问题描述] 据说鼎纹的 种制造 式是 铜模印出来的,这是我国古代劳动 智慧 的结晶.铜模印过的地 ,会留下深深的印记,经过时间的炼化,洗 练成历史的遗存. 聪明的古代劳动人民拥有一个 a ...

  5. Postman 下载和使用

    Postman 的官网下载地址是:https://www.getpostman.com/apps/

  6. 【leetcode算法-简单】28. 实现strStr

    [题目描述] 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle 字符串出现的第一个位置 (从0开始).如 ...

  7. Hive 数据类型及操作数据库

    3. Hive 数据类型 3.1 基本数据类型 Hive 数据类型 Java 数据类型 长度 TINYINT byte 1 byte 有符号整数 SMALINT short 2 byte 有符号整数 ...

  8. java - redis学习

    在学习redis之前,我们首先需要了解一下NoSQL(非关系数据库).非关系型数据库通常指数据以对象的形式存储在数据库中,而对象之间的关系通过每个对象自身的属性来决定. 为什么需要NoSQL? (1) ...

  9. Qt程序开机自动运行

    一.写入注册表需要管理员权限 1.开发中生成并运行程序需要写入注册表时,应该以管理员权限打开项目: 2.点击程序运行需要写入注册表,则应该以管理员权限打开此程序. 二.实现 void MoreSetW ...

  10. PHP之即点即改

    html: <td data-hide="1200" class="px12" id ="<?php echo $v['g_id'];?& ...