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 ...
随机推荐
- 6个WordPress备份插件
毫无疑问,为了保证网站的数据安全,经常备份是非常有必要的,当然手动备份比较麻烦,所以很多时候我们会使用WordPress的备份插件.Jackie Hole的<6 Top WordPress Ba ...
- HW3.8
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- Oracle10g/11g 在SUSE/RHEL上的安装与配置
在过去对众多项目的支撑过程中,Oracle作为首选数据库,其安装与配置过程成了重复性最多的工作之一.在此,我进行了总结,并分享出来,希望能对大家有所帮助.随着Oracle版本的提升,从9i -> ...
- SAP 使用SQL Trace(ST05)
SAP 使用SQL Trace(ST05) SAP R/3 提供标准ABAP SQL 跟踪工具.使用T-Code:ST05 可以进入追踪设定画面: 在Trace Modes 区域中选 ...
- Modelsim初级使用教程
来源 http://blog.sina.com.cn/s/blog_6c7b6f030101ctlh.html 一. Modelsim简介 Modelsim仿真工具是Model公司开发的.它支持Ver ...
- Mysql常见问题及优化
本文将就以下三个问题进行展开: 1.库表设计 2.慢 SQL 问题 3.误操作.程序 bug 时怎么办 一.库表设计 1.1 引擎选择 在 mysql 5.1 中,引入了新的插件式存储引擎体系结构,允 ...
- redis整合spring @Bean写法
jedis是一款java连接redis的客户端,spring基于jedis进行了封装,提供了简洁的操作redis的方法. 使用maven进行管理jar包之间的依赖: <dependency> ...
- ASP.NET- Repeater 嵌套
我们有时候需要查找出父菜单下面全部的子菜单,然后根据子菜单的ID查找出该类别下面的全部新闻. 通常往往只知道父级菜单的ID,但不知道父级菜单下面有多少个子菜单,也不知道子菜单的ID 所以我们往往需要根 ...
- OR 改写union数据变少
<pre name="code" class="sql">SQL> SELECT deptno FROM emp WHERE mgr = 76 ...
- Android史上功能最全的日历控件
※效果 ※用法 package com.fancyy.calendarweight; import java.util.ArrayList; import java.util.List; import ...