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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
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!