题目如下:

Arijit is a brilliant boy. He likes memory games. He likes to participate alone but this time he has to have a partner. So he chooses you.

In this Game , your team will be shown N numbers for few minutes . You will have to memorize these numbers.

Now, the questioner will ask you Q queries, in each query He will give you a number , and you have to tell him the total number of occurrences of that number in the array of numbers shown to your team . If the number is not present , then you will have to say “NOT PRESENT” (without quotes).

INPUT And OUTPUT

The first line of input will contain N, an integer, which is the total number of numbers shown to your team.

The second line of input contains N space separated integers .

The third line of input contains an integer Q , denoting the total number of integers.

The Next Q lines will contain an integer denoting an integer, Bi , for which you have to print the number of occurrences of that number (Bi) in those N numbers on a new line.

If the number Bi isn’t present then Print “NOT PRESENT” (without quotes) on a new line.

CONSTRAINTS

1≤N≤105

0≤Bi≤1000

1≤Q≤105

SAMPLE INPUT
 
 
6
1 1 1 2 2 0
6
1
2
1
0
3
4
SAMPLE OUTPUT
 
 
3
2
3
1
NOT PRESENT
NOT PRESENT
 
Explanation

The given array is (1,1,1,2,2,0) of size 6.

Total number of queries is 6 also.

For the first query i.e for 1 , the total of number of occurrences of 1 in the given array is 3 . Hence the corresponding output is 3.

For the second query i.e. for 2, the total of number of occurrences of 2 in the given array is 2 . Hence the corresponding output is 2.

For the fifth query i.e. for 3. 3 is not present in the array . So the corresponding output is "NOT PRESENT" (without quotes).

Time Limit:0.6 sec(s) for all input files combined.
Memory Limit:256 MB
Source Limit:1024 KB
Marking Scheme:Marks are awarded when all the testcases pass.
Allowed Languages:Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), TypeScript, Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic
 
 
https://www.hackerearth.com/zh/practice/data-structures/arrays/1-d/practice-problems/algorithm/memorise-me/description/
 
这道题的关键在于时间效率,因为有一个sample数据非常多,而这道题对时间的要求(0.6sec)远比空间要求(256MB)高,所以选择以空间换时间。
题目的关键在于数字的大小不会超过1000,所以可以创建一个大小为1001的数组(使用vector更好,初始化方便),然后用数字直接做地址记录频率。最后将所需数字的频率输出即可。

Memorise Me!——用数值做地址,实现快速查找的更多相关文章

  1. Java String Integer转换 练习:编程求字符串“100”和“150”按十进制数值做差后的结果以字符串形式输出。

    package com.swift; public class String_To_Integer_Test { public static void main(String[] args) { /* ...

  2. PHP实现文本快速查找 - 二分查找

    PHP实现文本快速查找 - 二分查找法 起因 先说说事情的起因,最近在分析数据时经常遇到一种场景,代码需要频繁的读某一张数据库的表,比如根据地区ID获取地区名称.根据网站分类ID获取分类名称.根据关键 ...

  3. Eclipse添加快速查找Dao中方法所对应的Mybatis XML映射SQL的插件

    Dao关联Mybatis快速查找的插件安装地址:http://dl.bintray.com/harawata/eclipse 安装步骤: ①Eclipse ==> Help ==> Ins ...

  4. jQuery实现的快速查找

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. vim之快速查找功能

    vim有强大的字符串查找功能. 我们通常在vim下要查找字符串的时候, 都是输入 / 或者 ?  加 需要查找的字符串来进行搜索,比如想搜索 super 这个单词, 可以输入  /super  或者 ...

  6. 如何快速查找到多个字典中的公共键(Key)---Python数据结构与算法相关问题与解决技巧

    如何快速查找到多个字典中的公共键(Key)-?   实际案例: 西班牙足球甲级联赛,每轮球员进球统计: 第1轮: { '苏亚雷斯':1,'梅西':2,'本泽马':1,...} 第2轮: { '苏亚雷斯 ...

  7. (私人收藏)[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例)

    [开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例) HTML5最全快速查找离线手册:https://pan.baidu.com/s/19seE8TJQSx4IsWgXtKQS0Aj9y ...

  8. (私人收藏)[开发必备]最全Java离线快速查找手册(可查询可学习,带实例)

    (私人收藏)[开发必备]最全Java离线快速查找手册(可查询可学习,带实例) https://pan.baidu.com/s/1L54VuFwCdKVnQGVc8vD1TQnwmj java手册 Ja ...

  9. [SQL Server]如何快速查找使用了某个字段的所有存储过程

    [SQL Server]如何快速查找使用了某个字段的所有存储过程       当一个系统中使用了很多的表,并且存在大量的存储过程,当数据库中的某个表删除了某个字段,那么相应的存储过程也需要改动,但是我 ...

随机推荐

  1. 如何在 windows server 2008 上面 挂载NFS

    首先, 你在一台服务器上面配置好NFS 服务器:然后按照一下步骤: mounting the nfs on windows server 2008 r2: open Windows Server 的D ...

  2. SQLServer之创建事务未提交读

    未提交读注意事项 使用 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED 指定会话的锁定级别. 一次只能设置一个隔离级别选项,而且设置的选项将一直对那个 ...

  3. chrome浏览器插件开发实例

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code   具体步骤: 1.新建 manifest.json 文件 { "name& ...

  4. PHP奇淫技巧

    https://www.jb51.net/list/list_67_1.htm PHP技巧:https://www.jb51.net/list/list_67_13.htm mysql三范式 1NF: ...

  5. pip 升级 pip

    For Python2 sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ --upgrade pip For Python3 ...

  6. IDEA+快捷键

    格式化代码:ctrl+alt+L IDEA快捷键管理:https://blog.csdn.net/h8178/article/details/78328097  (duplicate:为复制上一行)

  7. python2.7.14安装部署(Linux)

    +++++++++++++++++++++++++++++++++++++++++++标题:python2.7.14安装部署(Linux)时间:2019年2月23日内容:Linux下python环境部 ...

  8. 【zabbix教程系列】二、zabbix特点

    一.度量收集 从任何设备,系统,应用上收集指标,收集指标的方法有: 多平台zabbix代理 SNMP and IPMI 代理 无代理监控用户服务 自定义方法 计算和聚合 用户端web监控  二.问题发 ...

  9. Shell命令-文件及内容处理之cut、rev

    文件及内容处理 - cut.rev 1. cut:切割文件内容 cut命令的功能说明 cut 命令用于显示每行从开头算起num1 到 num2 的文字. cut命令的语法格式 cut [OPTION] ...

  10. rocketmq双主模式

    1.官网 https://rocketmq.apache.org/ 官方安装文档 https://rocketmq.apache.org/docs/quick-start/ 2.rocketmq多主配 ...