UVA
来源:互联网 发布:云计算安全事件 编辑:程序博客网 时间:2024/06/05 21:04
Description
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 41 3 2 2 4 3 2 11 32 43 24 2
Output for the Sample Input
2070
#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int N = 1000000 + 10;vector<int> a[N];int n, m;int main(){while(scanf("%d%d", &n, &m) != EOF){for(int i = 1; i <= n; i++) a[i].clear();for(int i = 1; i <= n; i++){int b;scanf("%d", &b);a[b].push_back(i);}while(m--){int k,v;scanf("%d%d", &k, &v);if(k > a[v].size() || a[v].size() == 0) printf("0\n");else printf("%d\n", a[v][k - 1]);}}return 0;}
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 用matlab解欧拉计划题目
- [图像]摄像机标定(1) 标定中的四个坐标系
- iOS保存联系人到系统通讯录
- c语言:找出N以内的所有素数
- NYOJ D : riba的名字
- UVA
- Python学习_我该怎样访问列表中的元素
- POJ1273 Drainage Ditches【dinic算法】
- jenkins部署到tomcat服务器上
- ctf学习笔记
- java语言
- Win7系统Visual Studio下的openCV环境配置
- 英语听力下载的网址
- java标号—continue,break用法详解