Hi all,
Today I was working on this problem. I recognize that this is a data structure problem, but I am curious on how to solve it with:
- Segtree + lazy propagation and 2.Binary indexed tree
Thank you much in advance!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Hi all,
Today I was working on this problem. I recognize that this is a data structure problem, but I am curious on how to solve it with:
Thank you much in advance!
Название |
---|
Just make a segment tree such that each node contains the sum of squres of numbers in its range and the sum of the numbers. For the first update what we are doing for each range while updating in fact is: (a[l]+c)^2 + (a[l+1]+c)^2.....(a[r]+c)^2 so since (a+b)^2=a^2 + 2ab + b^2 Then the last sum is equal to : (sum of the squres of current numbers of the range)+(2*c*(sum of current numbers of the range))+((r-l+1)*(c^2)) Where c is the number that we are increasing the interval by. The second update query is easy. And of course sum query is easy since we could do the update.
Do you use lazy propagation?
Yes of course.I submitted my solution and got AC. Here is my code Code.