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
/*
* Author: Joshua
* Created Time: 2014年07月10日 星期四 14时23分15秒
* File Name: uva11991.cpp
*/
#include<cstdio>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
int n,m;
map <int ,vector <int> > a; int main()
{
int x,y;
while (scanf("%d%d",&n,&m)==2)
{
a.clear();
for (int i=1;i<=n;i++)
{
scanf("%d",&x);
if (a.count(x)==0) a[x] = vector<int>();
a[x].push_back(i);
}
while (m--)
{
scanf("%d%d",&x,&y);
if (a.count(y) == 0 || a[y].size()<x ) printf("0\n");
else printf("%d\n",a[y][x-1]);
}
}
return 0;
}

  

uva11991 Easy Problem from Rujia Liu?的更多相关文章

  1. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  2. UVA-11991 Easy Problem from Rujia Liu?

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

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

  4. 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, ...

  5. 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, ...

  6. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

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

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

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

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

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

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

随机推荐

  1. 如何写出面试官欣赏的Java单例

    单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例的特殊类.通过单例模式可以保证系统中一个类只有一个实例. 今天我们不谈单例模式的用途,只说一说如果在面试的时候面试官让你敲一段代码 ...

  2. 【RequireJS】requireJS的基础知识

    1. requirejs的优点 1)异步加载依赖的文件 2)管理文件加载顺序 3)管理文件加载的包路径 2. requirejs下载地点 https://github.com/jrburke/requ ...

  3. PHP环境搭建——Apache

    1.PHP环境安装前我们需要知道PHP给我们带来的功能是什么? Php主要用在三个领域 (1)       网站和web应用程序 (2)       命令行脚本 (3)       桌面(GUI)应用 ...

  4. Android性能测试——Allocation Tracker(Device Monitor)

    Android性能测试--Allocation Tracker(Device Monitor) Allocation Tracker 能做什么? 追踪内存分配信息,按顺序排列,这样我们就能清晰看出来某 ...

  5. 利用Spring的ApplicationEvent执行自定义方法

    在Spring中已经定义了五个标准事件,分别介绍如下: 1)ContextRefreshedEvent:当ApplicationContext初始化或者刷新时触发该事件. 2)ContextClose ...

  6. java IO流整理

    Java流操作有关的类或接口: Java流类图结构: 流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...

  7. Linux - 简明Shell编程12 - 定制输出(ColorOutput)

    脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash echo -e "\ ...

  8. 社群系统ThinkSNS + 移动端研发周报

    社群系统"ThinkSNS+"对比ThinkSNS V4系列,ThinkSNS V4系列的产品规划主要偏重于企业服务应用,注重功能的覆盖面和用户关系的逻辑处理.Thin社群系统kS ...

  9. mac corntab定期执行任务

    mac corntab定期执行任务 crontab中的每一行代表一个定期执行的任务,分为6个部分.前5个部分表示何时执行命令,最后一个部分表示执行的命令.每个部分以空格分隔,除了最后一个部分(命令)可 ...

  10. SpringMVC详解(二)------详细架构

    通过上篇博客,我们能编写一个 SpringMVC 的入门实例,但是为什么要这样写?这样写有啥好处?通过这篇博客我们会有详细的了解. 本篇博客源码下载链接:http://pan.baidu.com/s/ ...