11991 - Easy Problem from Rujia Liu?

Time limit: 1.000 seconds

Problem E

Easy Problem from Rujia Liu?

Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets easy problem (for example, 'the Coco-Cola Store' in UVa OJ), to encourage more people to solve his problems :D

Given an array, your task is to find the k-th occurrence (from left to right) of an integer v. To make the problem more difficult (and interesting!), you'll have to answer m such queries.

Input

There are several test cases. The first line of each test case contains two integers n, m(1<=n,m<=100,000), the number of elements in the array, and the number of queries. The next line contains n positive integers not larger than 1,000,000. Each of the following m lines contains two integer k and v (1<=k<=n, 1<=v<=1,000,000). The input is terminated by end-of-file (EOF). The size of input file does not exceed 5MB.

Output

For each query, print the 1-based location of the occurrence. If there is no such element, output 0 instead.

Sample Input

8 4
1 3 2 2 4 3 2 1
1 3
2 4
3 2
4 2

Output for the Sample Input

2
0
7
0

Rujia Liu's Present 3: A Data Structure Contest Celebrating the 100th Anniversary of Tsinghua University
Special Thanks: Yiming Li
Note: Please make sure to test your program with the gift I/O files before submitting!

题解:STL map、vector的应用。

代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<stdbool.h>
#include<stdlib.h> #define rep(i,a,b) for(i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x)) using namespace std; map<int,vector<int> > a; int main()
{
int i,n,m,x,y; while(~scanf("%d%d",&n,&m)) { a.clear();
rep(i,,n) {
scanf("%d",&x);
if(!a.count(x)) a[x]=vector<int>();
a[x].push_back(i);
} while(m--) {
scanf("%d%d",&x,&y);
if(a[y].size()<x || !a.count(y)) printf("0\n");
else printf("%d\n",a[y][x-]);
}
} return ;
}

[UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]的更多相关文章

  1. uva 11991 - Easy Problem from Rujia Liu?(STL)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...

  2. CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu?

    CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...

  3. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  4. UVA 11991 Easy Problem from Rujia Liu?(vector map)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  5. UVA 11991 Easy Problem from Rujia Liu?【STL】

    题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142">https://uv ...

  6. STL UVA 11991 Easy Problem from Rujia Liu?

    题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...

  7. uva 11991 Easy Problem from Rujia Liu? vector+map

    水题 学习一下数据的存储方法. #include<iostream> #include<cstdio> #include<cstdlib> #include< ...

  8. 11991 - Easy Problem from Rujia Liu?(的基础数据结构)

    UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...

  9. uva--11991 - Easy Problem from Rujia Liu?(sort+二分 map+vector vector)

    11991 - Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for e ...

随机推荐

  1. 剑指offer中二进制中1的个数

    容易想到的是将n一位一位的和1进行比较,产生如下代码 但是这样的话会出下面的问题 那么就是原数据不动,将1依次移动进行比较有如下的代码 一种更简单的方法是: 这样做的思路是 总而言之

  2. redis maxmemory设置

    关于maxmemory的设置,如果redis的应用场景是作为db使用,那不要设置这个选项,因为db是不能容忍丢失数据的. 如果作为cache使用,则可以启用这个选项(其实既然有淘汰策略,那就是cach ...

  3. jquery 实现全选反选

    jquery代码 $(function () { $('#inputCheck').click(function () { if ($(this).attr("checked")) ...

  4. 《Unix环境高级编程》环境搭建

    用的是第三版的安装包:src.3e.tar.gz 地址:http://www.apuebook.com/ 1.解压:$ tar  -zxvf  *.tar.gz 2. $ cd apue.3e/ 3. ...

  5. ajax提交写法

    <script> /* ajax提交写法 */ function add_prize() { // var query={}; var query = new Object(); quer ...

  6. python3-day4(yield)

    1.yield 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外,迭代器的一 ...

  7. StroyBoard中UICollectionView中添加Header和footer

    到Storyboard中,选择collection view controller中的"Collection View".在Attributes inspector中,选择&quo ...

  8. mysql学习之五:sql语句学习3

    好吧,大家认为这样的字体还是比較好看,全部我们就换这样的字体了. INSERT INTO 语句用于向表格中插入新的行. 语法 INSERT INTO 表名称 VALUES (值1, 值2,....) ...

  9. C++ Primer 学习笔记_84_模板与泛型编程 --模板特化

    模板与泛型编程 --模板特化 引言: 我们并不总是能够写出对全部可能被实例化的类型都最合适的模板.某些情况下,通用模板定义对于某个类型可能是全然错误的,通用模板定义或许不能编译或者做错误的事情;另外一 ...

  10. SRM 588 D2 L3:GameInDarknessDiv2,DFS

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12710 采用DFS搜索,第一次写的时候忘了加访问标志,结果状态 ...