Problem Link: DD001

Problem:

Ram is a book seller. His shop is in Raipur.

He must handle requests which come in the following forms:

(1) a b : Insert a book with b pages at the end of the ath shelf.

(2) a b : Print the number of pages in the bth book on the ath shelf.

(3) a : Print the number of books on the ath shelf.

Raam has got an assistant, Priya. She is neighbour of Ram. Although inexperienced, Priya can handle all of the queries of types 2 and 3. Help Ram deal with all the queries of type 1. Priya has used two arrays:

int* total_number_of_books;

- This stores the total number of books on each shelf.

int** total_number_of_pages;

- This stores the total number of pages in each book of each shelf.
- The rows represent the shelves and the columns represent the books.

**Input Format**

The first line contains an integer total_number_of_shelves, the number of shelves in the library. The second line contains an integer total_number_of_queries, the number of requests. Each of the following total_number_of_queries lines contains a request in one of the three specified formats.

**Constraints**

1 <= total_number_of_shelves <= 10^5

1 <= total_number_of_queries <= 10^5

For each query of the second type, it is guaranteed that a book is present on the ath shelf at bth index.

0 <= a < total_number_of_shelves

Both the shelves and the books are numbered starting from 0.

Maximum number of books per shelf <= 1100.

**Output Format**

Write the logic for the requests of type 1. The logic for requests of types 2 and 3 are provided.

**Sample Input 0**

5

5

1 0 15

1 0 20

1 2 78

2 2 0

3 0

**Sample Output 0**

78

2

**Explanation 0**

There are 5 shelves and 5 requests, or queries.

- 1 Place a 15 page book at the end of shelf 0.
- 2 Place a 20 page book at the end of shelf 0.
- 3 Place a 78 page book at the end of shelf 2.
- 4 The number of pages in the 0th book on the 2nd shelf is 78.
- 5 The number of books on the 0th shelf is 2.

**Solution:**

#include<bits/stdc++.h>

typedef long long int ll;

using namespace std;

const int N = 1e5+10;

vectora[N];

int sh, q;

void solve(){

cin >> sh >> q;

while(q–) {

int t;

cin >> t;

if(t == 1) {

int p, sn;

cin >> sn >> p;

a[sn].push_back§;

} else if(t == 2) {

int b, sn;

cin >> sn >> b;

cout << a[sn][b] << “\n”;

} else {

int i;

cin >> i;

cout << (int)a[i].size() << “\n”;

}

}

}

int main(){

ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int t =1;

while(t–)

solve();

return 0;

}