uva 11991 - Easy Problem from Rujia Liu?

map的用法:

代码:

 1 #include<vector>
 2 #include<cstdio>
 3 #include<map>
 4 #define maxn 1000009
 5 using namespace std;
 6 
 7 vector<int>ve[maxn];
 8 map<int,vector<int> >mp;
 9 int n,m,x,y;
10 int main()
11 {
12     while(scanf("%d%d",&n,&m)!=EOF)
13     {
14         mp.clear();
15         for(int i=0;i<n;i++)
16         {
17             scanf("%d",&x);
18             if(!mp.count(x))mp[x]=vector<int>();
19             mp[x].push_back(i+1);
20         }
21         while(m--)
22         {
23             scanf("%d%d",&x,&y);
24             if(!mp.count(y)||mp[y].size()<x)puts("0");
25             else printf("%d\n",mp[y][x-1]);
26         }
27     }
28     return 0;
29 }
View Code

 

posted @ 2013-10-23 23:15  Yours1103  阅读(146)  评论(0编辑  收藏  举报