Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор jha_gaurav98, история, 7 лет назад, По-английски

I was solving the question PSHTRG. Basically it is a segment tree problem. I stored 45 greatest elements of each range as the node in segment tree and then for each query I used these elements to find the answer. But my code is giving TLE. I think there is nothing wrong with the logic but I am not able to optimize the code. Please can someone help. Thanks in advance.

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

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Your update function works in O(N).You must add this "if(l > x || r < x) return;" to make it O(logN). And then your code should be accepted.