题目大意:求第k个v的编号
方法很多,这里给出比较快的,用STL中的map和vector
#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
const int N=1000005;
map<int,vector<int> >ma;
int n,m;
int main(){
freopen("Uva.in","r",stdin);
freopen("Uva.out","w",stdout);
while((scanf("%d%d",&n,&m))==2){
ma.clear();
for(int i =1; i<=n;i++){
int x;
scanf("%d",&x);
if(!ma.count(x))ma[x]=vector<int>();//新建vector
ma[x].push_back(i);
}
for(int i = 1; i<= m; i++){
int k,v;
scanf("%d%d",&k,&v);
if(!ma.count(v) ||ma[v].size()<k)//don't forget the second one
printf("0\n");
else printf("%d\n",ma[v][k-1]);
}
}
return 0;
}