#P14188. [ICPC 2024 Hangzhou R] Barkley III

    ID: 14061 Type: RemoteJudge 5000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>线段树2024位运算ICPC均摊分析杭州

[ICPC 2024 Hangzhou R] Barkley III

题目描述

There are nn little pigs in Pigeland. All of them are proficient in competitive programming, and the ii-th of them has aia_i rating. If kk pigs p1,p2,,pkp_1, p_2, \cdots, p_k form a team, the rating of the team will be $a_{p_1}\ \&\ a_{p_2}\ \&\ a_{p_3}\ \& \cdots \&\ a_{p_k}$, where &\& denotes the bitwise AND operation.

There are some programming contests to take place. Pigeland can send exactly one team to participate in each contest. For the ii-th competition, only the pigs numbered between lil_i and rir_i (both inclusive) have time to participate. Unfortunately, due to a shortage of funds, exactly one pig numbered between lil_i and rir_i has to be removed. Meanwhile, all other pigs in the interval will participate in the contest. Pig-head, the coach of Pigeland, needs to properly select pigs who will not participate so that the team's rating is maximized.

However, through training and participating in contests, the rating of pigs may be changed. As Pig-head's best friend, your task is to maintain the pigs' rating for the following qq events belonging to three types.

  • 1  l  r  x1 \; l \; r \; x: Pig-head changes the rating of each pig numbered between ll and rr (both inclusive) by executing the bitwise AND operation with xx. More formally, for all lirl \le i \le r, aia_i becomes ai & xa_i\ \&\ x.
  • 2  s  x2 \; s \; x: Pig-head changes the rating of the ss-th pig to xx.
  • 3  l  r3 \; l \; r: Pig-head asks for the maximum rating when forming a team by selecting pigs numbered between ll and rr (both inclusive) and removing exactly one of them.

输入格式

There is only one test case in each test file.

The first line contains two integers nn and qq (2n1062 \le n \le 10^6, 1q1061 \le q \le 10^6) indicating the number of pigs and the number of events.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n (0ai<2630 \le a_i < 2^{63}) where aia_i indicates the rating of the ii-th pig.

For the following qq lines, the ii-th line first contains an integer opiop_i (opi{1,2,3}op_i \in \{1, 2, 3\}) indicating the type of the ii-th event. If opi=1op_i = 1, then three integers ll, rr, and xx follow (1lrn1 \le l \le r \le n, 0x<2630 \le x < 2^{63}); If opi=2op_i = 2, then two integers ss and xx follow (1sn1 \le s \le n, 0x<2630 \le x < 2^{63}); If opi=3op_i = 3, then two integers ll and rr follow (1l<rn1 \le l < r \le n).

输出格式

For each event of the third type, output one line containing one integer indicating the maximum rating of the team.

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