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 ...
随机推荐
- Weka 自动优化参数
import weka.core.*; import weka.classifiers.*; import weka.classifiers.meta.*; import weka.classifie ...
- (android 源码下开发应用程序) 如何在 Android 各 level ( 包含 user space 與 kernel space ) 使用dump call stack的方法
http://janbarry0914.blogspot.com/2014/07/androiddump-call-stack.html dump call stack [文章重點] 了解 Andro ...
- SAP一句话入门 .
SD是Sales and Distribution的简称.在SAP系统中,销售与分销模块处在供应链下游,关注从客户订单到向客户收款的全过程. SD模块中的Sales好理解,而Distribution却 ...
- hdoj 3861 The King’s Problem【强连通缩点建图&&最小路径覆盖】
The King’s Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- JVM之---Java内存分配参数(第四篇)
1.内存分配参数---大纲 Ø如何设置堆内存 Ø如何设置栈内存 Ø如何设置方法区 Ø如何设置对的分配比率 Ø设置参数打印堆栈: ØJava程序的两种模式:Server&Client 2.设置堆 ...
- nginx 重装添加http_ssl_module模块
起因: 如果出现“[emerg] 10464#0: unknown directive "ssl" in /usr/local/nginx-0.6.32/conf/nginx.co ...
- 转载 yii2-按需加载并管理CSS样式/JS脚本
一.资源包定义 Yii2对于CSS/JS 管理,使用AssetBundle资源包类. 创建如下: backend/assets/AppAsset.php namespace backend\asset ...
- Js/Jquery- Base64和UrlEncode编码解码
最近几天遇到一些URL参数明文显示的问题,因为是明文显示,容易让人通过改变参数查看到他没有权限看到内容. 一开始我的做法是自定义了规则,然后原始的那种URL编码.可是URL编译后效果不理想,他无法编译 ...
- SQL Server:OA权限管理设计的实现 下
SQL Server:OA权限管理设计的实现 下 OA系统权限管理设计方案 不同职责的人员,对于系统操作的权限应该是不同的.优秀的业务系统,这是最基本的功能. 可以对“组”进行权限 ...
- 使用freemarker生成html
http://herryhaixiao.iteye.com/blog/677524 由于freemarker这个技术很久很久就有了,注释我就没写得很详细了,相信大家都看得懂.下面就直接上代码以及一些代 ...