luogu#P11071. 「QMSOI R1」 Distorted Fate

「QMSOI R1」 Distorted Fate

Background

O Fortuna velut luna statu variabilis……

(Image from Phigros artwork. Please contact for removal if needed.)

Enhanced version of T512613.

Problem Description

Geopelia needs to capture a special kind of gravitational wave, different from a black hole.

The ii-th gravitational wave has a frequency AiA_i. Multiple gravitational waves will affect each other and stack together, forming a gravitational wave with a faster frequency.

Specifically, for a sequence AA of length nn, the frequency after stacking all gravitational waves in AA is f(A)=i=1nAif(A)=\bigcup\limits_{i=1}^n A_i, where \bigcup denotes bitwise OR.

Now, Geopelia needs to know the sum of frequencies of several intervals that start from the same gravitational wave.

That is, Geopelia asks you for the value of:

i=lrf(A[l,i])\sum_{i=l}^r f(A[l,i])

where A[l,r]A[l,r] is the sequence formed by Al,Al+1,,Ar1,ArA_l,A_{l+1},\cdots,A_{r-1},A_r.

Unfortunately, due to the gravitational influence of the Azure Boundary, in some interval [l,r][l,r], the frequencies of all gravitational waves might be XORed with a value xx.

Geopelia wants to update her data in real time. Can you help her?

She knows the frequencies may be very large, so you only need to tell her the answer mod 230\bmod \ 2^{30}.

Formal Statement

Given an array AA of length nn, you need to perform the following qq operations.

  1. 1 l r x XOR AiA_i with xx for all lirl\le i\le r.

  2. 2 l r Compute:

(i=lrj=liAj)mod230(\sum_{i=l}^r\bigcup_{j=l}^i A_j) \bmod 2^{30}

where \bigcup denotes bitwise OR.

Input Format

The first line contains two integers nn and qq, representing the number of gravitational waves and the number of operations.

The second line contains nn integers. The ii-th integer is the initial frequency AiA_i of gravitational wave ii.

Then follow qq lines. Each line contains three integers opt,l,ropt,l,r.

If opt=1opt=1, an additional integer xx is given, meaning to XOR the frequencies in interval [l,r][l,r] with xx.

If opt=2opt=2, it means this is a query.

Output Format

For each query, output one integer per line, representing the result of the expression mod 230\bmod \ 2^{30}.

3 3
1 2 3
2 1 3
1 1 2 2
2 1 3
7
9

Hint

Sample Explanation

For the first query: at this time A={1,2,3}A=\{1,2,3\}, so the answer is 1+12+123=1+3+3=71+1\cup 2+1\cup 2\cup 3=1+3+3=7.

For the second query: at this time A={3,0,3}A=\{3,0,3\}, so the answer is 3+30+303=3+3+3=93+3\cup 0+3\cup 0\cup 3=3+3+3=9.

Constraints

This problem uses bundled testing with subtasks. The score for each subtask is as follows:

Subtask nn qq Time Memory Score
00 100\le 100 1s1s 512MB512MB 2020
11 2×104\le 2\times 10^4
22 2×105\le 2\times 10^5 3s3s
33 100MB\color{red}100MB 4040

For all testdata, 0ai,x<2300\le a_i,x< 2^{30}, 1lrn1\le l\le r\le n.

INITALIZING……
SCANING……
CONNECTING……__PhigrOS Client Login
TIME_OUT!
CONNECTING……__Unknown
SUCCESS!
————————
……Nine……Bird……
……Dove……!
……Hello?
…Can you hear me?
Dove?![SIGNAL LOST]

Translated by ChatGPT 5