/** * 做这题主要是根据演算法笔记里面的数据这边来做的, * 同时复习下vector,本题采用vector,时间复杂度为O(1) * **/ #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <map> using namespace std; int main() { int n, m, tmp, v; unsigned k; while(scanf("%d%d", &n, &m) != EOF) { map<int, vector<int>> mymap; for(int i = 0; i < n; i ++) { scanf("%d", &tmp); if(!mymap.count(tmp)) mymap[tmp] = vector<int>(); mymap[tmp].push_back(i); } for(int i = 0; i < m; i ++) { scanf("%d%d", &k, &v); if(!mymap.count(v) || k > mymap[v].size()) printf("0\n"); else printf("%d\n", mymap[v].at(k-1) + 1); } mymap.clear(); } return 0; }
UVA 11991 Easy Problem from Rujia Liu?,布布扣,bubuko.com
UVA 11991 Easy Problem from Rujia Liu?
原文:http://blog.csdn.net/zone_programming/article/details/21116679