luogu#P4991. 愤怒的XiaoX

愤怒的XiaoX

Background

For Q&A, please go to https://www.luogu.org/discuss/show?postid=79498.

A few days ago, in a mock contest, XiaoXXiaoX got AKAK again and again.

He wanted to make things harder for everyone, so he created the following problem.

Problem Description

Given a sequence, you need to maintain the following operations:

11 ll rr kk: bitwise NOT the last kk bits of the numbers from ll to rr.

22 ll rr kk: reverse the last kk bits of the numbers from ll to rr.

33 ww: query the value at position ww.

To reduce the difficulty of this problem, we make the following rules:

For operations on the sequence, the kk values are fixed within a certain range.

There are a total of tt different kk values.

After each kk, there are some operations.

In these operations, the kk (the number of modified bits) is the same.

Definition of bitwise NOT:

For example, the binary representation of a number is:

10100111

After taking bitwise NOT on the last 5 bits, it becomes:

10111000

Definition of reverse:

For example, the binary representation of a number is:

10100111

After reversing the last 5 bits, it becomes:

10111100

Input Format

The first line contains two integers nn and tt, representing the length of the sequence and the number of kk values.

The second line contains nn numbers, representing the initial sequence.

Then follow tt groups of operations. For each group, the first line contains two numbers qiq_i and kik_i, representing the number of operations and the value of kk used in these operations.

The next qiq_i lines describe the operations in this group.

Output Format

For each operation of type 33, output one line with one integer, representing the answer.

5 2
665667089 948925818 1118302620 288255565 1682529647 
5 2
1 3 4
3 1
2 3 5
2 2 4
3 4
5 25
1 3 3
1 3 4
3 1
2 1 5
2 1 3
665667089
288255566
665667089

Hint

For 10%10\% of the data, there are no operations of type 11 or 22.

For another 10%10\% of the data, there are no operations of type 11.

For another 10%10\% of the data, there are no operations of type 22.

For 50%50\% of the data, t1t \le 1.

For 70%70\% of the data, t2t \le 2.

For 100%100\% of the data, t5t \le 5, 1n500001 \le n \le 50000, 1qi200001 \le q_i \le 20000, k25k \le 25. The initial sequence is generated by rand()rand()rand() * rand() (on Windows).

Thanks to @swhsz for verifying the problem.

Translated by ChatGPT 5