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!
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 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| 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!