势能!(到0不用更新,直接返回)
现在给定一个长度为 NN 的序列,现在要对这个序列进行 MM 次操作,
AND : L , R , vAND:L,R,v 将区间中元素a_iai? (L \leqslant i \leqslant R)(L?i?R),将 a_iai? 修改为a_iai? & v ,(&是按位与)
UPD:X , v:UPD:X,v: 将 a[x] 修改为 v
QUE:L , R:QUE:L,R: 询问 a_iai? 的最大值(L \leqslant i \leqslant R)(L?i?R)
宋老板希望你能够写一个程序,支持以上操作。Tips:Tips:(1 \leqslant(1?vv\leqslant? 2^{30} - 1230?1) ,(1 \leqslant L,R,x \leqslant n)(1?L,R,x?n)
Input
第一行包括两个数字N,MN,M(1 \leqslant N,M \leqslant 400000)(1?N,M?400000),分别表示序列的长度和多少次操作
第二行包括 NN 个数字a_1,a_2...a_na1?,a2?...an?表示序列的初始状态 (1 \leqslant(1?a_i~ai? \leqslant?2^{30}230)
接下来的 MM 行,每一行都描述一种操作。
Output
对于每一个 QUEQUE 操作输出一个整数表示答案。 数据保证一定会有至少一次 QUEQUE 操作.
Example
Input
5 11
5 6 7 8 9
AND 1 3 5
UPD 1 10
AND 3 4 2
UPD 1 7
QUE 1 5
AND 2 5 8
AND 4 5 3
UPD 4 1
QUE 1 5
UPD 3 12
QUE 1 5
Output
9
7
12
View problem
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
此题注意 位运算的魅力。
推荐博客:(17条消息) 势能线段树(吉司机线段树)专题_jibinquan的博客-CSDN博客_势能线段树