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!

# | User | Rating |
---|---|---|

1 | tourist | 3686 |

2 | LHiC | 3330 |

3 | wxhtxdy | 3329 |

4 | Benq | 3315 |

5 | Um_nik | 3301 |

6 | sunset | 3279 |

7 | V--o_o--V | 3275 |

8 | yutaka1999 | 3190 |

9 | Radewoosh | 3179 |

10 | Petr | 3115 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 193 |

2 | Radewoosh | 184 |

3 | rng_58 | 163 |

4 | PikMike | 162 |

5 | Vovuh | 159 |

6 | 300iq | 153 |

7 | Petr | 148 |

7 | majk | 148 |

9 | Um_nik | 147 |

10 | neal | 144 |

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!

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/19/2019 22:43:56 (f3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

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.