I want to know the fast algorithm to solve this simple problem:
- You are given a sequence
a[0], a[1],..., a[N - 1]
. - You are given
Q
queries. All queries are query 1 or 2. Process all queries.- You are given integers l, r, x. Update
a[i] = max(a[i], x) for l <= i <= r
. - You are given integers l, r. Find
a[l] + a[l + 1] + ... + a[r]
.
- You are given integers l, r, x. Update
I only have a naive O(NQ)
algorithm, so please find more faster algorithm because I want to solve for N <= 200000, Q <= 200000
.