Java List ⬀
For this problem, we have 2 types of queries you
can perform on a
List:
- Insert
yat indexx:
Insert
x y
- Delete the element at index
x:
Delete
x
Given a list, L, of N integers, perform Q
queries on the list. Once all queries are completed, print the modified list as a single line of space-separated integers.
- The first line contains an integer,
N(the initial number of elements inL). - The second line contains
Nspace-separated integers describingL. - The third line contains an integer,
Q(the number of queries). - The
2Qsubsequent lines describe the queries, and each query is described over two lines:- If the first line of a query contains the String
Insert, then the second line contains two
space separated integers
xy, and the valueymust be inserted intoLat indexx. - If the first line of a query contains the String
Delete, then the second line contains index
x, whose element must be deleted fromL.
- If the first line of a query contains the String
Insert, then the second line contains two
space separated integers
1 ≤ N ≤ 40001 ≤ Q ≤ 4000- Each element in is a 32-bit integer.
Print the updated list L as a single line of
space-separated integers.
5
12 0 1 78 12
2
Insert
5 23
Delete
0
0 1 78 12 23
L = [12,0,1,78,12]Q₀: Insert23at index5.L₀ = [12,0,1,78,12,23]Q₁: Delete the element at index0.L₁ = [0,1,78,12,23]
Having performed all Q queries, we print L₁ as a
single line of space-separated integers.