11991 - Easy Problem from Rujia Liu?

Time limit: 1.000 seconds

Problem E

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

Rujia Liu's Present 3: A Data Structure Contest Celebrating the 100th Anniversary of Tsinghua University
Special Thanks: Yiming Li
Note: Please make sure to test your program with the gift I/O files before submitting!

题解:STL map、vector的应用。

代码:

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<stdbool.h>
#include<stdlib.h> #define rep(i,a,b) for(i=(a);i<=(b);i++)
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x)) using namespace std; map<int,vector<int> > a; int main()
{
int i,n,m,x,y; while(~scanf("%d%d",&n,&m)) { a.clear();
rep(i,,n) {
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[y].size()<x || !a.count(y)) printf("0\n");
else printf("%d\n",a[y][x-]);
}
} return ;
}

[UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]的更多相关文章

  1. uva 11991 - Easy Problem from Rujia Liu?(STL)

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

  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练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

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

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

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

  6. STL UVA 11991 Easy Problem from Rujia Liu?

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

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

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

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

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

  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. 深入理解7816(4)---关于T=1

    之前说过的T=0协议,基本上相当于是透明的数据,也就是说从应用的角度看,通过T=0传递的TPDU数据信息大都可以直接转换为对应的APD命令响应数据,“字节”是T=0协议最小的数据传输单元. 对于T=1 ...

  2. BZOJ1430: 小猴打架

    1430: 小猴打架 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 328  Solved: 234[Submit][Status] Descripti ...

  3. bzoj 1192

    http://www.lydsy.com/JudgeOnline/problem.php?id=1192 好像学过一个东西: [0..2^(N+1)-1]内的数都的都可以由2^0,2^1,...,2^ ...

  4. bzoj1151

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1151 状压DP,枚举前面4个,使得环型变线型. #include<cstdio> ...

  5. ASP.NET文件组成(转载于Owen的BLOG)

    一.扩展名: .aspx:窗体文件,为前台程序. .cs文件:类文件,主要为后台数据处理,供所有的.aspx文件的后台应用. .asmx文件:用于创建从其他应用程序使用的web服务的类. .css文件 ...

  6. Android自定义ListView的Item无法响应OnItemClick的解决办法

     转: 如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也 ...

  7. Android 百度地图API(01)_开发环境 HelloBaiduMap

    转载于:http://blog.csdn.net/lmj623565791/article/details/37729091 转载于:http://blog.csdn.net/crazy1235/ar ...

  8. Sonar入门(四):Eclipse集成Sonar

    sonar及其插件在项目中的使用方法 Sonar平台 Sonar平台的安装见一文, 在Sonar平台上进行的检查可以通过hudson进行触发, A. 没有做持续集成的项目可以复制以下hudson上的任 ...

  9. neural style论文解读

    相关的代码都在Github上,请参见我的Github,https://github.com/lijingpeng/deep-learning-notes 敬请多多关注哈~~~ 概述 在艺术领域,艺术家 ...

  10. SQL函数简述

    数字函数ABS 取绝对值 POWER 乘方 LN 10为底数取幂SQRT 平方根 EXP e的n次乘方 LOG(m,n) m为底数n取幂数学运算函数:ACOS ATAN ATAN2 COS COSH ...