Easy problem from rujia Liu?
Time limit:1000 ms |
|
Memory limit:Unknown |
|
64bit Io format:% LLD & % LlU |
[Submit]
[Go Back] [Status]
Description
Problem eeasy 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
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 5 MB.
Output
For each query, print the 1-based location of the occurrence. If there is no such element, output 0 instead.
Sample Input
8 41 3 2 2 4 3 2 11 32 43 24 2
Output for the sample input
2070
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!
Stored with map and vector.
#include<cstdio>#include<map>#include<vector>using namespace std;map<int ,vector<int> > mm;int main(){ int n,m,a, k,v; while(scanf("%d%d",&n,&m)==2){ mm.clear(); for(int i=1;i<=n;i++){ scanf("%d",&a); mm[a].push_back(i); } while(m--){ scanf("%d%d",&k,&v); if(mm[v].size()<k) printf("0\n"); else printf("%d\n",mm[v][k-1]); } } return 0;}