博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva11991 Easy Problem from Rujia Liu?
阅读量:4958 次
发布时间:2019-06-12

本文共 1971 字,大约阅读时间需要 6 分钟。

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 41 3 2 2 4 3 2 11 32 43 24 2

Output for the Sample Input

2070 代码:
#include
#include
#include
#include
using namespace std ;#define MAX 1000010vector
qe[MAX] ;int main(){ int Max = 0 , i , k , n , m , u ; while( scanf( "%d%d" , &n , &m )!= EOF ) { for( i = 1; i <= Max ; i++) qe[i].clear() ; Max = 0 ; for( i = 1; i <= n ;i++) { scanf( "%d" , &u ) ; qe[u].push_back( i ) ; if( Max < u) Max = u ; } while( m-- ) { scanf( "%d%d" , &k , &u ) ; if( k > qe[u].size() || 0 == qe[u].size() ) printf( "0\n" ) ; else printf( "%d\n" , qe[u][k-1] ) ; } }}

 

转载于:https://www.cnblogs.com/20120125llcai/archive/2013/05/11/3072505.html

你可能感兴趣的文章
【伯乐在线】每个程序员都该知道的编码准则
查看>>
Priority_queue详解
查看>>
痛苦的版本对齐
查看>>
C++内存分配
查看>>
programming review (c++): (2)binary tree, BFS, DFS, recursive, non-recursive
查看>>
windows 查看端口占用情况
查看>>
php基础-字符串处理
查看>>
Java中的注解以及应用 @Deprecated @SupressWarning @Override
查看>>
oracle自治事务(PRAGMA AUTONOMOUS_TRANSACTION)
查看>>
6.5.4稀疏表示与基筛选
查看>>
Codeforces Round #310 (Div. 2)简洁题解
查看>>
.Net Sokcet 异步编程
查看>>
tp js结合时间戳
查看>>
复杂网络
查看>>
http协议讲解
查看>>
随笔第一页
查看>>
Python 如何用列表实现栈和队列?
查看>>
android 127.0.0.1/localhost connection refused,在模拟器上应该用10.0.2.2访问你的电脑本机...
查看>>
js/javascript format json(js/javascript 格式化json字符串)
查看>>
Nginx从听说到学会
查看>>