UVa : 11991 (Easy Problem from Rujia Liu?)



// http://uva.onlinejudge.org/external/119/11991.html
// Tag: Data Structure, Vector
// Runtime: 0.228s

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define LL unsigned long long
#define N 1000005

using namespace std;

vector <int> res [N];

int main ()
{
	int n, m;
	int a [N];
	
	while ( scanf ("%d %d", &n, &m) != EOF ) {
		for ( int i = 0; i < n; i++ ) scanf ("%d", &a [i]);
		
		for ( int i = 0; i < N; i++ ) res [i].clear ();
		
		for ( int i = 0; i < n; i++ ) res [a [i]].push_back (i + 1);
		
		int k, v;
		
		for ( int i = 0; i < m; i++ ) {
			scanf ("%d %d", &k, &v);
			if ( res [v].size () < k ) printf ("0\n");
			else printf ("%d\n", res [v] [k - 1]);
		}
	}

    return 0;
}

One thought on “UVa : 11991 (Easy Problem from Rujia Liu?)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s