majay1638's blog

By majay1638, history, 3 years ago, In English

Hi guys, I am trying to solve segment tree question on cses . my Python solution passes only 1 test case and gives me TLE, but c++ solution get accepted, i tried to look online optimize python solution but still no luck , if you can help me to optimize my code it would be great .

problem : https://cses.fi/problemset/task/1648

My code Link : code link

Thanks

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Hi! I suggest you to keep solving problems in C++. Python is squite slower and Time Limit in CSES is quite tight. I don´t know python very much but you one thing you can try, is to find any other method to read input and print output faster. There are lots of queries and that could be the cause.

In addition, I can see that most of people solved this problem in C++, and only few people solve in Python with best execution time of 0.8 seconds.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it