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

题目大意:给出一个包含n个整数的数组,你需要回答若干询问。每次询问两个整数k和v,输出从左到右第k个v的下标(数组下标从左到右编号为1~n)

代码如下:

 #include<cstdio>
#include<vector>
#include<map>
using namespace std; map<int, vector<int> > a; // 最后两个>不要连写,否则会被误认为>> int main() {
int n, m, x, y;
while(scanf("%d%d", &n, &m) == ) {
a.clear();
for(int i = ; i < n; i++) {
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.count(y) || a[y].size() < x) printf("0\n");
else printf("%d\n", a[y][x-]);
}
}
return ;
}

UVA 11991 Easy Problem from Rujia Liu?(vector map)的更多相关文章

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

  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)

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

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

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

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

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

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

  7. STL UVA 11991 Easy Problem from Rujia Liu?

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

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

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

  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. nyoj 27 水池数目

    水池数目 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地 ...

  2. Unity手游之路<六>游戏摇杆之Easy Touch 3教程

    之前已经介绍过Unity自带的摇杆Joystick,它用起来很简单.但是它也存在很多局限,不能全部满足普通mmo手游的一些需求,例如:要能方便地更好素材:能指定在某个区域显示,或者只有在该区域触摸时才 ...

  3. JBPM学习(三):管理流程定义

    概念: ProcessDefinition,流程定义:一个流程的步骤说明,如一个请假流程.报销流程.是一个规则. ProcessDefinition,流程定义对象,是解析.jpdl.xml文件得到流程 ...

  4. JSON.NET概述

    1. JSON.NET概述 当JSON逐渐成为Ajax的标准数据交互格式时,在.NET中处理JSON数据只能使用字符串拼接的方法,十分麻烦,因而催生了JSON.NET这个项目. JSON.NET是一个 ...

  5. zend studio-如何更改字符集

    在加载一个项目的过程中很时候会因为字符集的不匹配从而导致项目文件显示为乱码,zend studio开发工具应该如何设置字符集呢: 打开[windows]-[preference]-[workspace ...

  6. ubuntu14.04源代码安装postgresql 9.1

    项目须要使用gisgraphy,怎奈gisgraphy3.0仅仅支持postgis1.5.因此仅仅能安装老版本号的posgresql和postgis了.从postgis的support matrix图 ...

  7. Centos6下yum安装MariaDB5.5(转)

    原文地址:http://www.cnblogs.com/kgdxpr/p/3209009.html vi /etc/yum.repos.d/MariaDB.repo 加入下面内容 [mariabd]n ...

  8. hdu1002大数相加

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. sizeof strlen strncpy用法总结 结构体实际所占内存大小 以及memset用法

    sizeof测类型(数组名除外) strlen测实际长度 strncpy返回指针类型 #include <stdio.h> #include <stdlib.h> #inclu ...

  10. Mysql实时双备

    设置方法: 步一设 A 服务服 (192.168.1.43) 上用户为 backup, 123456 , 同步的数据库为test; B 服务服 (192.168.1.23) 上用户为 root, 12 ...