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 ...
随机推荐
- 使用CPU探查器优化XAML程序
如果您正在开发一个使用 XAML (是否是 c + +. C# 或 VB) 的 Windows 商店应用程序,还有一个好的机会来提高应用程序的性能.为了帮助完成这一点,我们所有在售的能够应用开发 Wi ...
- sql执行计划
http://www.cnblogs.com/kissdodog/p/3160560.html
- Weka 自动优化参数
import weka.core.*; import weka.classifiers.*; import weka.classifiers.meta.*; import weka.classifie ...
- POJ3009 Curling 2.0
正式做POJ的第一题,做出来后又看了别人的代码,就又完善了一下,也通过了.参考 http://blog.sina.com.cn/s/blog_4abcd9bc0100phzb.html 改了之后觉得写 ...
- JS多态
面向对象语言有三大特征,前面介绍了封装和继承,那么JS作为一门面向对象语言,有多态么,又怎么实现多态呢? 我们先看看多态的概念: 多态:同一操作作用于不同的对象,可以有不同的解释,产生不同的执行结果. ...
- 手动建立数据库连接的BaseDAO
package com.chinasoft.julong.dao; import java.sql.Connection; import java.sql.DriverManager; import ...
- C#基础知识学习手记1
这篇随笔主要用来记录我在C#学习过程做的笔记,算作是一门课程中的小知识点吧. 1. 变量和表达式 1.1 如何在输出带有引号(英文双引号.英文单引号)以 ...
- Android架构分析之Android消息处理机制(二)
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android版本号:4.4.2 在上一篇文章中我们看了一个使用Handler处理Message消息的样例,本文我们 ...
- STM8S TIM4库函数应用
void TIM4_TimerInit(u8 Timer4Time) { assert_param(IS_TIM4TIMERTIME_OK(Timer4Time)); TIM4_DeInit();// ...
- Win7 64bit 安装VisualSVN出现报错:Servic 'VisualSVN Server' failed to start.解决办法
问题描述: Win7 64bit 安装VisualSVN时出现报错: Servic 'VisualSVN Server' failed to start.Please check VisualSVN ...