6802.List Removals

Time Limit: 1s Memory Limit: 512MB

You are given a list consisting of $n$ integers. Your task is to remove elements from the list at given positions, and report the removed elements.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the initial size of the list. During the process, the elements are numbered $1,2,\dots,k$ where $k$ is the current size of the list.

The second line has $n$ integers $x_1,x_2,\dots,x_n$ : the contents of the list.

The last line has $n$ integers $p_1,p_2,\dots,p_n$ : the positions of the elements to be removed.

  • $1 \le n \le 2 \cdot 10^5$
  • $1 \le x_i \le 10^9$
  • $1 \le p_i \le n-i+1$

Output Format(To the terminal/stdout)

Print the elements in the order they are removed.

Sample Input

Copy
5
2 6 1 4 2
3 1 3 1 1
 \n
 · · · · \n
 · · · · \n

Sample Output

Copy
1 2 2 6 4
 · · · · \n

The contents of the list are $[2,6,1,4,2]$ , $[2,6,4,2]$ , $[6,4,2]$ , $[6,4]$ , $[4]$ and $[]$ .

Source: CSES, Range Queries, 1749

Submit

请先 登录

© 2025 FAQs