Skip to content

Instantly share code, notes, and snippets.

@s25g5d4
Created June 12, 2015 18:32
Show Gist options
  • Save s25g5d4/b40a83d1bce2d989bd56 to your computer and use it in GitHub Desktop.
Save s25g5d4/b40a83d1bce2d989bd56 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <cstring>
int main()
{
using namespace std;
while (true) {
int n, m;
cin >> n >> m;
if (cin.eof())
break;
static int vtable[1000000];
int vcount = 0;
vector< vector<int> > occurence;
memset(vtable, 0, sizeof (vtable));
int i = 0;
while (n--) {
int u;
cin >> u;
--u;
if (vtable[u] == 0) {
vtable[u] = ++vcount;
occurence.push_back({++i});
}
else
occurence[vtable[u] - 1].push_back(++i);
}
while (m--) {
unsigned int k, v;
cin >> k >> v;
--k;
--v;
if (vtable[v] == 0 || occurence[vtable[v] - 1].size() <= k)
cout << '0' << endl;
else
cout << occurence[vtable[v] - 1][k] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment