https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142题意:给一个长"/>

UVA 11991Easy Problem from Rujia Liu?STL

Posted gavanwanggw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA 11991Easy Problem from Rujia Liu?STL相关的知识,希望对你有一定的参考价值。

题目链接:
php?

option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142">https://uva.onlinejudge.org/index.php?

option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142

题意:
给一个长度n的序列。有m询问,每一个询问会问第k个出现的数字的下标是多少
用map记录

代码:

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>

using namespace std;

int n, m;
map<int ,vector<int> > mp;

int c[1001000];

int main()
{
    while (~scanf("%d%d", &n, &m))
    {
        mp.clear();
        memset(c, 0, sizeof(c));

        int tmp;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", &tmp);
            mp[tmp].push_back(i);
        }
        int a, b;
        while (m--)
        {
            scanf("%d%d", &a, &b);
            if (mp[b].size() < a) printf("0\n");
            else printf("%d\n", mp[b][a - 1]);
        }
    }
    return 0;
}

以上是关于UVA 11991Easy Problem from Rujia Liu?STL的主要内容,如果未能解决你的问题,请参考以下文章

UVA 11991 Easy Problem from Rujia Liu?

UVA 11991 Easy Problem from Rujia Liu? 简单STL

uva 11991

uva11991

UVA 11991 求第k个数值为v的下标

[uva11991]map和vector的入门