UVA 11991 Easy Problem from Rujia Liu?
用map 和vector很巧妙的解决了
#include<iostream> #include<cstdio> #include<map> #include<vector> using namespace std; map <int, vector<int> > a; int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { a.clear(); int temp,k,v; for(int i=0;i<n;i++) { scanf("%d",&temp); a[temp].push_back(i+1); } while(m--) { scanf("%d%d",&k,&v); if(a[v].size()<k) printf("0\n"); else printf("%d\n",a[v][k-1]); } } }
新 blog : www.hrwhisper.me