水题一枚,将每个元素与保存它出现位置的vector建立成一个map即可,代码如下:
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
map<int,vector<int>> data;
int main(){
int n, m, x, y;
while(scanf("%d%d", &n, &m) != EOF){
for(int i = 0; i < n; i++){
scanf("%d", &x);
data[x].push_back(i+1);
}
for(int i = 0; i < m; i++){
scanf("%d%d", &x, &y);
if(!data.count(y) || data[y].size() < x)
printf("0\n");
else
printf("%d\n", data[y].at(x-1));
}
}
return 0;
}