Yukino With Subinterval
Yukino has an array a_1, a_2 \cdots a_na1,a2⋯*a**n*. As a tsundere girl, Yukino is fond of studying subinterval.
Today, she gives you four integers l, r, x, yl,r,x,y, and she is looking for how many different subintervals [L, R][L,R] are in the interval [l, r][l,r] that meet the following restraints:
- a_L =a_{L+1} =\cdots=a_RaL=aL+1=⋯=aR, and for any i \in [L,R], x \le a_i \le yi∈[L,R],x≤ai≤y.
- The length of such a subinterval should be maximum under the first restraint.
Note that two subintervals [L_1,R_1] , [L_2,R_2][L1,R1],[L2,R2]are different if and only if at least one of the following formulas is true:
- L1 \cancel= L2L1=L2
- R1 \cancel= R2R1=R2
Yukino, at the same time, likes making tricks. She will choose two integers pos,vpos,v, and she will change a_{pos}*apo**s* to vv.
Now, you need to handle the following types of queries:
- 11 pos vpos v: change a_{pos}*apo**s* to vv
- 22 l r x yl r x y: print the number of legal subintervals in the interval [l, r][l,r]
Input
The first line of the input contains two integers n, m (1 \le n, m \le 2 \times 10^5)n,m(1≤n,m≤2×105) – the numbers of the array and the numbers of queries respectively.
The second line of the input contains nn integers a_i (1 \le a_i \le n)ai(1≤ai≤n).
For the next mm line, each containing a query in one of the following queries:
- 11 pospos vv (1 \le pos, v \le n)(1≤pos,v≤n): change a_{pos}*apo**s* to vv
- 22 l r x yl r x y (1 \le l \le r \le n) (1 \le x \le y \le n)(1≤l≤r≤n)(1≤x≤y≤n): print the number of legal subintervals in the interval [l,r][l,r]
Output
For each query of the second type, you should output the number of legal subintervals in the interval [l, r][l,r].
样例输入复制
6 3
3 3 1 5 6 5
2 2 3 4 5
1 3 2
2 1 6 1 5
样例输出复制
0
4
样例解释
For the first operations, there are 33 different subintervals ([2, 2],[3, 3],[2,3])([2,2],[3,3],[2,3]) in the interval [2, 3][2,3], but none of them meets all the restraints.
For the third operations, the legal subintervals in interval [1, 6][1,6] are: [1, 2], [3, 3], [4, 4], [6, 6][1,2],[3,3],[4,4],[6,6]
Notes that although subintervals [1,1][1,1] and [2,2][2,2] also meet the first restraint, we can extend them to subinterval [1, 2][1,2]. So the length of them is not long enough, which against the second one.
题目链接:https://nanti.jisuanke.com/t/41356
题意:
给你一个含有n个数的数组,和m个操作
操作1:
将a[pos] 变为val
操作2:
询问在\([l,r]\) 中有多少个子区间满足数值在$[x,y] $ 之间 ,每一个子区间是长度尽可能大的相同数字。
思路:
将数组中 $a[i] $ ,转为在二维坐标平面上的点\((i,a[i])\) ,
那么就转为了一个带修改的二维平面中询问矩阵内点权值和的问题。
这是一个经典的三维偏序问题。
可以用CDQ分治来解决。
不会的话可以先学习一下这题:
https://www.cnblogs.com/qieqiemin/p/11613573.html
本题还需要注意几点:
因为连续相同的数值只贡献一个,所以我们把连续相同的只把第一个点放入平面中(即放入cdq的离线操作中)
那么对于每一个询问,我们就要特判一下\((l,a[l])\) 这个点,如果\(a[l]\) 在 \([x,y]\) 之间,并且 满足
$l >1 $
$a[l]==a[l-1] $
这2个条件,都需要对这个询问的答案加上1。即加上a[l]为开头的子区间的贡献,
以及修改操作,需要判断改变\(a[i]\) 对\(a[i-1],a[i+1]\) 的影响,以及如果更改前的\(a[i]\) 是一个子区间的开头,需要去掉原来的影响(加上相反的值即可。)
代码:
#include
#include
#include
#include
#include
#include
#include
#include