2D-Segment Tree VS 2D- BIT ?

Правка en2, от mehthemez, 2015-06-15 02:10:31

Hello. I've doing a problem on poj.com ( link : http://poj.org/problem?id=1195 )

The main idea of the problem is that we are given a S * S grid and there is 2 kind of operations.

Operation 1 : Change the cell x, y by adding a certain value A.

Operation 2 : Answer the sum of the rectangle which is defined by the two points; top leftmost : (l, b), bottom rightmost (r, t)

So obviously we need a 2D Binary Indexed Tree (because of operation 1). I tried to implement a 2D Segment Tree, but I'm getting a TLE.

Can someone help me figure out why ? Are Segment Trees not efficient here or my implementation of 2D Segment Tree is just bad ?

Link to my C++ code (getting TLE): http://pastebin.com/KA3UXm3N

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский mehthemez 2015-06-15 17:03:19 10
en3 Английский mehthemez 2015-06-15 02:12:37 5 Tiny change: 'o. \nI've doing a p' -> 'o. \nI've been doing a p'
en2 Английский mehthemez 2015-06-15 02:10:31 24 Tiny change: 'in value A\nOperatio' -
en1 Английский mehthemez 2015-06-15 02:07:43 754 Initial revision (published)