Hello all
Can anyone tell me how to solve this problem?
Query 1 — Equate all elements in range l to r equal to x
Query 2 — Find sum of all the elements from range l to r.
Constraints : n < = 100000
Hello all
Can anyone tell me how to solve this problem?
Query 1 — Equate all elements in range l to r equal to x
Query 2 — Find sum of all the elements from range l to r.
Constraints : n < = 100000
# | User | Rating |
---|---|---|
1 | tourist | 3843 |
2 | jiangly | 3705 |
3 | Benq | 3628 |
4 | orzdevinwang | 3571 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | jqdai0815 | 3530 |
8 | ecnerwala | 3499 |
9 | gyh20 | 3447 |
10 | Rebelz | 3409 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 164 |
3 | adamant | 162 |
4 | TheScrasse | 159 |
5 | nor | 153 |
5 | maroonrk | 153 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
9 | orz | 145 |
10 | pajenegod | 144 |
Name |
---|
This is classic segment tree with lazy propagation problem, just use google or etc...
Can you share the code?
I am new to segment trees and I am finding it tough to code the update part.
code
Thanks for your code. :)
It worked.
By the way, can we do the same update thing using a fenwick tree?
I think it's impossible to assign value on segment, using fenwick tree :(
Any particular reason for this?
read about fenwick trees
Hi, you can learn a lot from here: Easy and efficient segment trees
Basically your query 1 is a interval modification using lazy propagation (calculating only the values you need when you need them) and the query 2 is a basic range query. Everything is explained in the link I provided. GL