luogu#P4883. mzf的考验

mzf的考验

Background

mzfmzf is determined to become a hero. Of course, he is also an OIerOIer. He hopes that besides being good at OIOI, he can also do many other things, such as psychology, guitar, flirting, and so on. To be more attractive, he does not hunch his back, does not stay up late, works out all day, and has bright eyes. He is the least like an OIerOIer in our computer room. However, after being out of place with us for several days and thoroughly studying the I Ching, he could not stand our weird comments about him, and he exploded. At that moment, it felt like the sky was falling and the earth was collapsing. It was like the end of the world.

Problem Description

The Eight Trigrams are Qian, Kun, Zhen, Xun, Kan, Li, Gen, and Dui. Combining them in pairs, one on top and one below, forms the sixty-four hexagrams. Each hexagram has six lines, making a total of 384 lines. Lines are divided into yin and yang. A yang line is strong, and a yin line is soft. The world is vast, and anything can happen. All kinds of strange things come from here. After thoroughly studying the I Ching, mzfmzf drew nn strange patterns. He said they were a stronger divination system improved by him. Each pattern has 20 rows. Each row is either a yin line (0)(0) or a yang line (1)(1). As OIersOIers, we can view each hexagram as a binary string. He drew these nn patterns on talismans, and then performed mm operations:

Operation 1: Reverse the patterns in interval [l,r][l,r], for example, (3,1,2,5)(3,1,2,5) becomes (5,2,1,3)(5,2,1,3).

Operation 2: mzfmzf draws a new hexagram, and XORs all hexagrams in [l,r][l,r] with this newly drawn hexagram.

Operation 3: mzfmzf asks other people in the computer room for the sum of the weights (values) of the binary numbers represented by the hexagrams in [l,r][l,r].

If we cannot correctly answer every Operation 33, then the feng shui layout of the computer room will change, and we will all...!

Since mzfmzf, in his madness, tied us all up, we can only beg you to help us solve this problem.

Input Format

The first line contains two positive integers: nn, mm (nn is the length of the sequence, and mm is the number of operations).

The second line contains nn positive integers: a[i]a[i] (each hexagram is given in decimal)(1<=i<=n)(1<=i<=n).

Next mm lines: each line starts with a positive integer optopt indicating the operation type.

  1. opt=1opt=1: two positive integers: l,rl,r. Please reverse interval [l,r][l,r].
  2. opt=2opt=2: three positive integers: l,r,dl,r,d. Please XOR every hexagram in [l,r][l,r] with hexagram dd. (0d<2200\le d\lt 2^{20})
  3. opt=3opt=3: two positive integers: l,rl,r. Please query the sum of hexagram weights in interval [l,r][l,r].

Output Format

For each case of opt=3opt=3, output one line with the answer.

8 9
4 6 2 1 7 9 10 2
1 1 4
3 1 6
2 4 5 2
3 1 6
2 1 5 8
3 1 6
2 5 7 10
3 4 7
3 1 8

29
29
69
24
59

Hint

For 20%20\% of the testdata, n1000n\le1000, m1000m\le 1000.

For another 20%20\% of the testdata, there is no Operation 11.

For another 20%20\% of the testdata, it is guaranteed that nn is a power of 22, and in Operation 11, it is guaranteed that l=i×(2j)+1l=i\times(2^j)+1, r=(i+1)×(2j)r=(i+1)\times(2^j), where i,ji,j can be any values.

For 100%100\% of the testdata, n105n\le 10^5, m5×104m\le 5\times 10^4, 1lrn1\le l\le r\le n, 0d<2200\le d<2^{20}.

Translated by ChatGPT 5