一开始以为这道题用for循环就可以做出来,结果还是把题想简单了,这么多for肯定超时啊,后来想想决定用新学的map(新手不太会啊,但前几天已经做了好多次学校出的关于map的OJ题,大概还是了解一点的,,尽管如此还是查了好长时间的百度才做出这道题),不会这道题的可以好好看看map;最后还是献上我的小代码,
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
map<int,vector<int>> s;
int main()
{
int m,n,a;
while(scanf("%d %d",&m,&n)!=EOF){
s.clear();
for(int i=1;i<=m;i++){
scanf("%d",&a);
s[a].push_back(i);
}
while(n--){
int q,p;
scanf("%d %d",&q,&p);
if(s[p].size()<q)
printf("0\n");
else{
printf("%d\n",s[p][q-1]);
}
}
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-38351.html