You start with an empty array arr. You are given a 2D integer array queries where each queries[i] = [type, value]. Process the queries in order:
-
If
type == 1
, append
value
to the end of
arr
.
-
If
type == 2
, replace every element currently in
arr
with its bitwise XOR with
value
.
An XOR operation only affects elements that are present in the array at the moment it is applied. Elements appended later must not be affected by earlier XOR operations.
Return the final array arr in insertion order.
Function Signature
def process_queries(queries: list[list[int]]) -> list[int]:
...
Rules
-
Each query is a pair
[type, value]
, processed from first to last.
-
A type-2 query on an empty array changes nothing.
-
If there is no type-1 query, return an empty list.
Constraints
-
1 <= queries.length <= 2 * 10^5
-
queries[i].length == 2
-
queries[i][0]
is either
1
or
2
-
0 <= queries[i][1] < 2^30
Examples
Input: queries = [[1,5],[2,3],[1,7],[2,1]]
Output: [7,6]
The array becomes [5], then [6] after the XOR with 3, then [6, 7]. The final XOR with 1 turns 6 into 7 and 7 into 6.
Input: queries = [[2,4],[1,1],[1,2],[2,7]]
Output: [6,5]
The first XOR runs on an empty array and has no effect. After the two appends the array is [1, 2], and XOR with 7 gives [6, 5].