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

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

Hi people, I just learnt about segment tree and did this problem. It involves alternate OR and XOR operations to obtain final result. My python solution(time complexity -> O(nlogn)) runs fine with smaller number in the array(see Test: #7) but as the numbers grow, I am getting TLE. Can anyone tell, how I can overcome this?

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

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

first :here is your accepted code ,I just add a wrapper function called bootstrap and some few changes in recursions like change return with yield and add @boostrap decorator above any recursion function, you can search about bootstrap wrapper in codeforces blogs. second : I advice you to use bottom up segment tree not recursive version because python is very bad about resolving recursions as its stack not efficient ,here is my accepted code and see the difference in time execution between my code and your recursive code.

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thank you so much for the help and advice man, I didn't expected that much clear explanation.