Question: uva11991easy problem from rujia Liu? (MAP + vector)
Give you n numbers, which may be repeated. Then, in m queries, ask the subscript of the k V. If such a number does not exist, output 0.
Solution: map each number and subscript for one-to-one ing, but because the same number appears multiple times, an array is required and the length is not certain, so vector is used.
Code:
# Include <cstdio> # include <map> # include <vector> using namespace STD; Map <int, vector <int> vis; // do not concatenate int main () {int n, m; int v, k; while (scanf ("% d", & N, & M )! = EOF) {vis. clear (); // clear for (INT I = 1; I <= N; I ++) {scanf ("% d", & V); If (! VIS. count (V) vis [v] = vector <int> (); // create an array vis [v]. push_back (I) ;}for (INT I = 0; I <m; I ++) {scanf ("% d", & K, & V ); if (! VIS. count (v) | Vis [v]. size () <k) printf ("0 \ n"); elseprintf ("% d \ n", vis [v] [k-1]);} return 0 ;}
Uva11991easy problem from rujia Liu? (MAP + vector)