Hello everyone!
Can someone tell me how to make update on segment (from l to r)?
If you can write a code, please send me.
Thanks for attention!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello everyone!
Can someone tell me how to make update on segment (from l to r)?
If you can write a code, please send me.
Thanks for attention!
Name |
---|
Ex: Now, I want to add w for each elements on segment and I want to get sum on Segment My UpDate Code
http://pastie.org/10009594. Sum from l to r and add e from l to r
What do you need — only update or update + sum queries? Post the problem statement if it is possible.
Here is statement :
Given n, and array A(all numbers less than 10^9).
Then given m, and m requests :
1) + l r d, add to all numbers from l to r d (1 <= l <= r <= n, 0 <= d <= 10^9).
2) * l r d, multiply to all numbers from l to r d (1 <= l <= r <= n, 0 <= d <= 10^9).
3) ? p, print p-th number modulo 10^9 + 7.
P.S This problem from Republic olympiad in Kazakhstan.
Okay, then my idea is a segment tree with two arrays for lazy propagation — lazy_add and lazy_mult.
If you need the sum for the interval stored in node Node, then you can get it with tree[Node]*lazy_mult[Node]+lazy_add[Node].
If you need to add t to the interval stored in node Node, then you can just do lazy_add[Node]+=t.
If you need to multiply by t the interval stored in node Node, then you can just do lazy_add[Node]*=t and then lazy_mult[Node]*=t.
And you should not forget to get the answer modulo 10^9+7 every time you do these operations :)
Thanks for help!