Skip to content

Instantly share code, notes, and snippets.

@NiteshOswal
Created January 23, 2016 20:35
Show Gist options
  • Save NiteshOswal/94f8f7b4afaa11676cd2 to your computer and use it in GitHub Desktop.
Save NiteshOswal/94f8f7b4afaa11676cd2 to your computer and use it in GitHub Desktop.
You are given N integer sequences and Q queries. Each query is in the following format: "a b" where a denotes the index of the sequence, and b denotes the index of the element in that sequence. Your task is to find the value of the element described in each query. Input Format The first line consists of N and Q separated by a space. The followin…
/*
2 2
3 1 5 4
5 1 2 8 9 3
0 1
1 3
*/
#include<iostream>
using namespace std;
int main() {
int n /*integer sequences*/, q /*queries*/, _nsize = 0;
int **sequences, **queries;
cin >> n >> q;
sequences = new int*[n]; //to store sequences
queries = new int*[q]; //to store queries
for(int sidx = 0; sidx < n; ++sidx) {
cin >> _nsize;
sequences[sidx] = new int[_nsize];
for(int _idx = 0; _idx < _nsize; ++_idx) {
cin >> sequences[sidx][_idx];
}
}
for(int qidx = 0; qidx < q; ++qidx) {
queries[qidx] = new int[2];
cin >> queries[qidx][0] >> queries[qidx][1];
}
for(int qidx = 0; qidx < q; ++qidx) {
cout << sequences[queries[qidx][0]][queries[qidx][1]] << endl;
}
delete [] sequences;
delete [] queries;
return 0;
}
Copy link

ghost commented Aug 3, 2016

hello, I'm currently learning cpp and came across your code, I'm having trouble with increment before processing the current statement, can you explain "++_idx" the line, starting from the second FOR (line 19), thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment