思路:给你一串数字,每次询问k,v,输出代表第K个V的下标,直接用STL搞搞
#include<iostream> #include<map> #include<vector> #include<cstdio> using namespace std; int main() { int n,q; while(scanf("%d%d",&n,&q)!=EOF) { map<int,vector<int> >mp; for(int i = 1;i<=n;i++) { int x; scanf("%d",&x); if(!mp.count(x)) { mp[x] = vector<int>(); mp[x].push_back(i); } else mp[x].push_back(i); } while(q--) { int v,k; scanf("%d%d",&k,&v); if(!mp.count(v)) { printf("0\n"); continue; } else { if (mp[v].size()<k) { printf("0\n"); continue; } else { printf("%d\n",mp[v][k-1]); } } } } }