Блог пользователя LIT2021015_AYUSH

Автор LIT2021015_AYUSH, история, 2 месяца назад, По-английски

Here we are given an array of size n (n<=1e5) and we are given to process q (q<=1e5) queries. Queries are of two types .The first one is a point update query. The second one tell us to calculate sum of all subarrays in the range (l to r) . More formarlly in second type of query we are given l and r and we have to find Σf(i,j) where l<=i<=j<=r and f(i,j) denotes the sum of subarray starting at i th index and ending at j th index.

Although I tried it using segment Tree but couldn't think of the optimal approach for this.

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Don't know why people downvote the blogs even after asking legit questions and that too after the contests.

»
2 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

say you want to merge [l1,r1] and [l2,r2] in seg tree then extra contribution of any element at index i in first range would be i*(r2-l2+1)*a[i] similarily for second range , so you just need summation of i*a[i] to merge intervals , you can use prefix sum to find it giving o(1) complexity for merging