查找数组中第k个v出现的位置,不存在输出0
用map<int,vector<int> > a;可以开二维不定长数组!
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
map<int,vector<int> > a;
int main(){
int n,m,x,y;
//freopen("a.txt","r",stdin);
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.count(y)||a[y].size()<x) printf("0\n");
else printf("%d\n",a[y][x-1]);
}
}
}