UVA 11991 Easy Problem from Rujia Liu?【STL】
阿新 • • 發佈:2017-06-17
dex space queue rom () ont cti process 代碼
題目鏈接:
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 11991 Easy Problem from Rujia Liu?【STL】