Insert(i, x)
Delete(i)
Reverse [L..R]
RelaxMax(L, R, x)
for i = L..R
a[i] = max(a[i], x)
GetSum(L, R)
----------------------------------------
Build, Split
[-----] [-----] [-----]
Insert (+)
Delete (+)
Reverse [L..R] :
pL = Split(L-1), pR = Split(R)
reverse(s + pL, s + pR)
for (i = pL; i < pR; i++)
s[i].reversed ^= 1
GetSum [L..R] :
pL = Split(L-1), pR = Split(R)
res = 0
for (i = pL; i < pR; i++)
res += s[i].sum
RelaxMax(L, R, x)
pL = Split(L-1), pR = Split(R)
for (i = pL; i < pR; i++) {
s[i].relaxMax = max(s[i].relaxMax, x)
s[i].sortedArray[]
s[i].array[] <--- max(s[i].relaxMax, array[j])
s[i].sum:
j = BS(s[i].sortedArray[], s[i].relaxMax)
s[i].sum = j * s[i].relaxMax
+ s[i].sortedArrayPrefixSum[j..n]
}
K = size of one part
Split: KlogK + N/K
-------------
Reverse: is_reversed ^= 1
Sum: sum
RelaxMax:
sortedArray[]
BS
RelaxMax, RelaxMin