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
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.
Thanks for the suggestion Monazo1997 , actually i'm new to CP world and i use Python for web development projects that's why it is hard for me to learn 2 language at the same time but let's see till where python can lead me :)
use fenwick tree https://pastebin.pl/view/ba1820c4
Thanks jlallas384 that works fine, Though i have to learn fenwick tree now :) .