UVA11991(map+vector 离散化处理)

时间:2021-05-16 06:14:52
UVA11991(map+vector 离散化处理)

   UVA11991(map+vector 离散化处理)
#include <iostream>                                              
#include<map>                                                    
#include<vector>                                                 
#include<string>                                                 
using namespace std;                                             
int d[10005];                                                    
int main(int argc, char *argv[])                                 
{                                                                
	map<int,vector<int> > a;                                        
	int n,m,x,y;                                                    
	while(~scanf("%d%d",&n,&m)){                                    
		a.clear();                                                     
		for(int i=0;i<n;i++){                                          
			scanf("%d",&x);                                               
			if(!a.count(x)) a[x]=vector<int>();                           
			a[x].push_back(i+1);                                          
		}                                                              
		while(m--){                                                    
			scanf("%d%d",&x,&y);                                          
			if(!a.count(y)||a[y].size()<x) printf("0\n");                 
			else printf("%d\n",a[y][x-1]);                                
		}                                                              
	}                                                               
	                                                                
	return 0;                                                       
}