首页 > 代码库 > UVA 11991 Easy Problem from Rujia Liu?

UVA 11991 Easy Problem from Rujia Liu?

STL数据结构(vector,map)基本操作

 

 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 #include <vector> 6 #include <map> 7 using namespace std; 8  9 int main (){10     int n,m;11     map <int,vector<int> > x;12     while (~scanf ("%d%d",&n,&m)){13         x.clear() ;14         for (int i=1;i<=n;i++){15             int a;16             scanf ("%d",&a);17             if (!x.count (a))       //判断是否为空;18                 x[a]=vector<int> {};19             x[a].push_back (i);20         }21         while (m--){22             int k,v;23             scanf ("%d%d",&k,&v);//cout<<x[v][k-1]<<endl;24             if (!x.count(v)||x[v].size()<k)25                 printf ("0\n");26             else printf ("%d\n",x[v][k-1]);27         }28     }29     return 0;30 }