Hi! First off, I just wanted to ask if this problem is solvable using segment trees: http://codeforces.net/problemset/problem/52/C
I wrote a solution which uses segment trees but it gives me TLE on test 8. Can you please give me a hint at least? That would be quite helpful.
Here is the code: http://codeforces.net/contest/52/submission/24460216 Thanks!
Yes it is, however it appears you are using them quite ineffectively. Judging by the following lines in your code it seems that for each inc function you are updating each element in the segment separately:
This is quite ineffective, if there were for example 200000 queries that update the whole array, your code will have running time . One possible way of improving time is a technique called lazy propagation, which lets you update any segment in time, bringing the overall complexity down to , which will pass.
segment tree has implementation your case: increment interval and query maximum (it's easy to convert query minimum).
Or see my submission