UVA11991
给出一个包含n个整数的数组,每次询问两个整数k和v,输出从左到右第k个v的下标(从1到n)
白书指导书的例题。。不过可以写的更短一点:
#include <stdio.h> #include <vector> #include <map> #include <iostream> using namespace std; map<int, vector<int> >a; int main(){ int n, m, x, y; while(scanf("%d%d", &n, &m) != EOF){ a.clear(); for(int i=0; i<n; i++){ scanf("%d", &x); a[x].push_back(i+1); } while(m--){ scanf("%d%d", &x, &y); if(a[y].size() < x) printf("0\n"); else printf("%d\n", a[y][x-1]); } } }
Greatness is never a given, it must be earned.