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, 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)的更多相关文章
- 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, ...
- CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu?
CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...
- uva 11991 - Easy Problem from Rujia Liu?(STL)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...
- 11991 - Easy Problem from Rujia Liu?(的基础数据结构)
UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector ...
- [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 ...
- UVA 11991 Easy Problem from Rujia Liu?【STL】
题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142">https://uv ...
- STL UVA 11991 Easy Problem from Rujia Liu?
题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...
- uva 11991 Easy Problem from Rujia Liu? vector+map
水题 学习一下数据的存储方法. #include<iostream> #include<cstdio> #include<cstdlib> #include< ...
- 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 ...
随机推荐
- 【Java基础】基本类型的包装类作为参数传递是值传递还是引用传递
突然想到这个问题,然后做了下实验,下面以Integer来讲解,其他的忽略: import java.util.Iterator; /** * Created by lili on 15/9/24. * ...
- Codeforces10D–LCIS(区间DP)
题目大意 给定两个序列,要求你求出最长公共上升子序列 题解 LIS和LCS的合体,YY好久没YY出方程,看了网友的题解,主要是参考aikilis的,直接搬过来好了 经典的动态规划优化. 用opt[i] ...
- centos git版本服务器配置
在服务器上安装git及做些操作 - 执行命令 ` sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-de ...
- eclipse安装插件checkstyle
最近听说了一个eclipse神器:checkstyle,可以帮助java开发人员规范代码,对我这种有代码洁癖的人来说,这有着不小的魔力啊,必然要安装试一试啊. 我最喜欢的安装方式是 输入一个安装网址, ...
- js关键字
这已经是我第二次遇到这个问题了..关于关键字,用来做函数的命名,,,在高清上没问题,标清上秒死...页面都出不来...wtf...做个记录.. js关键字http://www.itxueyuan.or ...
- 立体视觉-opencv中立体匹配相关代码
三种匹配算法比较 BM算法: 该算法代码: view plaincopy to clipboardprint? CvStereoBMState *BMState = cvCreateStereoBMS ...
- iOS 检测网络状态
一般有两种方式,都是第三方的框架,轮子嘛,能用就先用着,后面再优化. 一:Reachability 1.首先在AppDelegate.h添加头文件"Reachability.h", ...
- 关于lab4实验git+近期出国手续办理
1.下载mit jos lab4时遇到问题(关于git操作,使用,还需进一步理解) 遇到的问题 出现未合并(merge)完全的问题,操作:git add kern/init.c 之后在确认提交 方法二 ...
- vs调试 本地IIS
http://www.cnblogs.com/minesky/p/3389955.html 准备篇-配置IIS环境 网站发布到测试环境或者生产后,经常会出现各种让人解不开的疑问,想调试也调试不了.可以 ...
- [ES6] 22. Const
'const' keyword is for creating a read only variable, something you can never change once created. ' ...