A table whose rows have different lengths
There is a table that holds integers.
Each row of the table may hold a different number of values, and some rows hold no values at all.
At first the table has no rows.
Rows are numbered from 1.
There are six commands.
- new k v1 … vk: attach a new row holding k values at the bottom of the table.
k can be 0.
- copy i: attach a new row holding the same values as row i at the bottom of the table.
After that the two rows change independently.
- add i v: append one value v to the end of row i.
- set i j v: change the j-th value (counted from 1) of row i to v.
- del i: delete row i.
The rows below it move up by one number each.
- print i: print on one line the number of values k in row i followed by the k values, separated by single spaces.
If the row is empty, print just 0.
The row numbers and value positions in commands always exist.
The first line gives the number of commands q, and the next q lines give one command each.
Print one line for each print, and on the last line print the number of remaining rows and the number of values in the whole table, separated by a single space.
Try allocating memory separately for each row, as much as it needs (malloc, realloc and free in C, std::vector<std::vector<int>> in C++).
copy allocates a new block and copies the values into it, and del gives that row's block back.
- Input
- 1 ≤ q ≤ 50,000, -10⁹ ≤ v ≤ 10⁹.
The k values of allnewcommands add up to at most 100,000.
At any time the table has at most 5,000 rows and holds at most 500,000 values in all, the values copied bycopyadd up to at most 500,000, and the values printed byprintadd up to at most 30,000. - Output
- One line per
print, then a last line "rows values"
9 new 3 1 2 3 copy 1 set 2 1 9 add 1 4 new 0 add 3 -5 del 2 print 1 print 2
4 1 2 3 4 1 -5 2 5