XOR ranges

4.3

11 votes
Datastructures, Dynamic Programming, Algorithms, 1-D
Problem

You are given an array of A integers. You must perform Q queries on this array.

The queries must be one of the following types:

  1. x:  Add element x to the start of the array.
  2. x: Add element x to the end of the array.
  3. x y: Print the XOR elements from the indices ranging from x to y.

The array is 1-indexed.

For every query of type 3, print the answer to the query.

Input format

  • First line: q
  • Next q lines: Queries of types 1, 2, or 3 is provided

Output format

For every query of type 3, print the answer to the query.

Constraints

1q3×105

In the first and second type of queries, 0x109

In the third type of queries, 1xyn, where n is the current size of the array

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

2=2

297=12

62=8

2974=8

Editor Image

?