Facing problem in spoj RACETIME — Race Against Time

Правка en2, от adamantium, 2016-06-03 20:23:51

I tried this problem with segment tree first and got TLE. Then I used square-root but again got TLE. To solve the problem with square-root i used tree which size is sqrt(n) * sqrt(n), where n is the size of the array. In every block of the tree I kept sqrt(n) elements of the array sorted in ascending order. When update occur I push the element in a block where it's index remain and again sort this block. And when i got query operation for every block which is in the range I found how many elements are less than the given value. This can be done with binary search for every block. Please tell me where i should optimize my code. Here you can have a look at my code .

Теги square root, data structure, binary search, spoj

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский adamantium 2016-06-03 20:23:51 5288
en1 Английский adamantium 2016-06-03 20:21:42 6070 Initial revision (published)