Easy Proble from Rujia Liu? UVA11991

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string>    
#include <sstream>
#include <utility>   
#include <ctime>

using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;
using std::endl;

map<int, vector<int> > mp;

int main()
{
	int n, m;
	while(~scanf("%d%d", &n, &m))
	{
		int temp;
		mp.clear();
		for(int i = 1; i <= n; ++i)
		{
			scanf("%d", &temp);
			if(mp.find(temp) == mp.end())
				mp.insert(make_pair(temp, vector<int> (1, i)));
			else
				mp[temp].push_back(i);
		}
		int k, v;
		for(int i = 0; i < m; ++i)
		{
			scanf("%d%d", &k, &v);
			if(mp.find(v) != mp.end() && k <= mp[v].size())
				printf("%d\n", mp[v][k-1]);
			else
				printf("0\n");
		}
	}
	return 0;
}

你可能感兴趣的:(Easy Proble from Rujia Liu? UVA11991)