1. 程式人生 > >UVA11991 Easy Problem from Rujia Liu?(map+vector)

UVA11991 Easy Problem from Rujia Liu?(map+vector)

給你n個數(n<=10w,但是數值<=100w),現在要你回答m個查詢,對於每個查詢都是k和v,要求你回答原始資料中第k個v值出現的原始下標,如果不存在輸出0.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main()
{
    int n,m,v;
    while(~scanf("%d%d",&n,&m))
    {
        map<int,vector<int> >mp;
        for(int i=1;i<=n;i++)
        {scanf("%d",&v);
        if(mp.count(v)==0)
        mp[v]=vector<int>();
        mp[v].push_back(i);
        }

    while(m--)
    {
        int k,v;
        scanf("%d%d",&k,&v);
        if(mp[v].size()<k)
        printf("0\n");
        else
        printf("%d\n",mp[v][k-1]);
    }
}
return 0;
}