标签:style blog http color os 数据 io 2014
题意:给一个长度n的序列,有m询问,每个询问会问第k个出现的数字的下标是多少
思路:用map和vector搞,map[i][j]直接保存的就是数字i第j个出现,每次直接输出即可
代码:
#include <cstdio> #include <cstring> #include <vector> #include <map> using namespace std; int n, m; map<int, vector<int> > ans; int main() { while (~scanf("%d%d", &n, &m)) { int a, b; ans.clear(); for (int i = 1; i <= n; i++) { scanf("%d", &a); if (!ans.count(a)) ans[a] = vector<int> (); ans[a].push_back(i); } while (m--) { scanf("%d%d", &a, &b); if (ans[b].size() < a) printf("0\n"); else printf("%d\n", ans[b][a - 1]); } } return 0; }
11991 - Easy Problem from Rujia Liu?(基础数据结构),布布扣,bubuko.com
11991 - Easy Problem from Rujia Liu?(基础数据结构)
标签:style blog http color os 数据 io 2014
原文地址:http://blog.csdn.net/accelerator_/article/details/38119349