// Prepare -> C++ -> Introduction // Consider an n-element array, , where each index i in the array contains a reference to an array // of k integers (where the value of k varies from array to array). See the Explanation section // below for a diagram. // Given a, you must answer queries. Each query is in the format i j, where i denotes an index in // array a and j denotes an index in the array located at a[i]. For each query, find and print the // value of element in the array at location a[i] on a new line. #include using namespace std; int f(int nn, int qq, vector> arrays_in, vector> queries) { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n, q; vector> v; ///////////////// //cin >> n >> q; n = nn, q = qq; // read arrays for (int i = 0; i < n; i++) // iterate over arrays { int num_elem; ///////////////// //cin >> num_elem; num_elem = arrays_in[i][0]; v.push_back(vector{}); for (int j = 0; j < num_elem; j++) { int val; ////////////// //cin >> val; val = arrays_in[i][j+1]; v[i].push_back(val); } } // read queries, print results for (int i = 0; i < q; i++) { int vector_num, index_to_read; ////////////////////////////////////// // cin >> vector_num >> index_to_read; vector_num = queries[i][0]; index_to_read = queries[i][1]; cout << v[vector_num][index_to_read] << endl; } for (int j = 0; j < n ; j++ ) { for (auto& i: v[j]) { cout << i << " "; } cout << endl; } return 0; } int main(void) { // Sample input // 2 2 // 3 1 5 4 // 5 1 2 8 9 3 // 0 1 // 1 3 // The first line contains two space-separated integers denoting the respective values of n(the // number of variable-length arrays) and q(the number of queries). // Each line of the subsequent lines contains a space-separated sequence in the format k a[i]0 // a[i]1 … a[i]k-1 describing the k-element array located at a[i]. // Each of the subsequent lines contains two space-separated integers describing the respective // values of i(an index in array ) and j(an index in the array referenced by a[i]) tuple>, vector>> testCase = // n q k, arr k, arr i,j i,j { 2, 2, {{3, 1,5,4},{5, 1,2,8,9,3}}, {{0,1},{1,3}} }; f(get<0>(testCase), get<1>(testCase), get<2>(testCase), get<3>(testCase)); return 0; }