Yes, I too guess this problem required some smart optimizations with the constant factors playing a big role!.
Even my own Java soln TLE’d, maybe due to overload operations with ArrayList.
But later I came to know the test cases for this problems where not too heavy.
This soln : CodeChef: Practical coding for everyone , has a time complexity of O(q * n) in worst case , no doubt this soln had the expected implementation of persistent segment trie.
See a lot of O(N * Q) solutions out there passing, they did not have any test case with all numbers same and all queries as 1 to N. I hope these test cases are added in the practice section.
Sorry about the weak testcases. This is first my problem. I will make sure this never happens again. I will add some testcases in the practice section. And about the timelimit, my idea was to use persistent trie for each subtree. This can be built by first building persistent tries of all child subtrees and then adding all nodes in subtrees of small children to trie of big child. This takes O(n logn logMAXN) to create and for each query it takes O(Q logMAXN). My solution took 1.17s to run. So I kept timelimit to 2s. Sorry for that. Here is my solution for reference: My solution
Because they take long time after every contest.
And If they provide editorials on time then someone may say that they are breaking their third tradition. CodeChef Traditions (Unoffical)
I can understand such instances…
That why advice to keep time limit a bit lenient… My solution( for CCIRCLES) was passing in 0.05 secs while people did the exactly same code and just replaced long long int by double and it took 0.80 secs for them.
Luckily I kept time limit 1 sec.
So it is sometimes unpredictable (for noob problem setters like me at least )