题目如下:

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. LeetCode算法题-Assign Cookies(Java实现)

    这是悦乐书的第234次更新,第247篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第101题(顺位题号是455).假设你是一个很棒的父母,并想给你的孩子一些饼干.但是,你 ...

  2. Jenkins插件之显示构建时间

    1.进入jenkin插件管理器中,安装  Timestamper 插件 2.安装完成后,进入到构建任务里面,在 构建环境 中勾选  Add timestamps to the Console Outp ...

  3. linux目录2

    19.linux注释多行 20.防火墙 21.创建逻辑卷 22.两台主机,ssh端口不同,如何拷贝文件    

  4. GRE与VXLAN

    一 GRE 1.1 概念 GRE全称是Generic Routing Encapsulation,是一种协议封装的格式,具体格式内容见:https://tools.ietf.org/html/rfc2 ...

  5. Python两大佬互相撕逼 技术何苦为难技术?

    最近两天 Python 圈发生了一件大事,两个 Python 大佬撕逼了起来了. 不,其实是一个大佬(刘志军)被怼. 事情是这样的. 背景 人物介绍: 董明伟:公众号「Python 之美」的作者,似乎 ...

  6. Golang 入门 : 切片(slice)

    切片(slice)是 Golang 中一种比较特殊的数据结构,这种数据结构更便于使用和管理数据集合.切片是围绕动态数组的概念构建的,可以按需自动增长和缩小.切片的动态增长是通过内置函数 append( ...

  7. iview table行render渲染不同的组件

    table不同的行,相同的列渲染不同的组件,如图1:第一行渲染selece,第二行渲染input render:(h,params)=>{ if(params.index === 0){ //以 ...

  8. CodeForces Round #553 Div2

    A. Maxim and Biology 代码: #include <bits/stdc++.h> using namespace std; int N; string s; int mi ...

  9. centos7只rsync+inotify

    环境: 操作系统:centos7.4 192.168.1.238 客户端 192.168.1.239 服务端 环境准备: 1.安装以下安装包lrzsz是xshell上传下载的安装包,可以忽略. yum ...

  10. Python——封装

    广义上面向对象的封装:代码的保护,面向对象的思想本身是一种保护,只让自己的对象能调用自己累的方法 狭义上的封装——面向对象的三大特性之一  属性.方法都隐藏起来,不让你看见 规则: 1.所有的私有,都 ...