FIICode 2025 Qualifying Round - Elevi | Iggy and Bits

This was the problem page during the contest. Access the current page here.
Time limit: 2s Memory limit: 256MB Input: Output:

Task

Iggy the martian absolutely loves bitwise operations, and to celebrate his love for them he has prepared the following challenge for you:

He has given you his favorite integer array [a1,a2,a3,,an][a_1, a_2, a_3,\ldots, a_n], after which he commanded you to perform qq tasks. A task can be one of the following:

  1. Replacement operation. Given pp and xx, Iggy wants you to replace apa_p with xx.
  2. And operation. Given ll, rr, xx, Iggy wants you to replace aia_i with (ai&x)(a_i \& x) for each ii (lirl \le i \le r), where &\& denotes the bitwise AND operation.
  3. Print operation. Given ll and rr, tell Iggy the value of i=lrai\displaystyle \sum_{i=l}^{r} a_i.

Input data

The first line will contain one integer, nn (1n1051 \le n \le 10^5).
The second line will contain nn integers, a1a_1, a2a_2, a3a_3, ..., ana_n (1ai1091 \le a_i \le 10^9).
The third line will contain one integer, qq (1q105)1 \le q \le 10^5).
Each of the next qq lines begins with a number cc (c{1,2,3}c \in \{1, 2, 3\}).
If c=1c = 1, it will be followed by two integers pp and xx (1pn;1x1091 \le p \le n; 1 \le x \le 10^9).
If c=2c = 2, it will be followed by three integers ll, rr and xx (1lrn;1x1091 \le l \le r \le n; 1 \le x \le 10^9).
If c=3c = 3, it will be followed by two integers ll and rr (1lrn1 \le l \le r \le n).

Output data

Print the answers for the type 33 tasks, one on each line.

Example

stdin

12
18 13 10 2 8 1 5 5 11 10 13 19 
7
3 3 4
1 6 19
2 5 12 5
1 2 4
1 9 2
3 7 12
3 2 9

stdout

12
18
29

Explanation

After the second task, the array becomes: [18,13,10,2,8,19,5,5,11,10,13,19][18,13,10,2,8,19,5,5,11,10,13,19].
After the third task, the array becomes: [18,13,10,2,0,1,5,5,1,0,5,1][18,13,10,2,0,1,5,5,1,0,5,1].
After the fourth task, the array becomes: [18,4,10,2,0,1,5,5,1,0,5,1][18,4,10,2,0,1,5,5,1,0,5,1].
After the fifth task, the array becomes: [18,4,10,2,0,1,5,5,2,0,5,1][18,4,10,2,0,1,5,5,2,0,5,1].

Log in or sign up to be able to send submissions!