i am getting TLE for both segment tree and BIT

Segment Tree solution
Fenwick Tree solution
Can anyone help??


I think when you are so sure about your solution . You should look for some submission which are easily available on the internet . I have also solved this problem but you have coded it in java so it will difficult for me to look at your code if you need i can provide my code to you …

Cheers codechef
Wishing you a very happy new year dude :smiley:

@ma5termind Happy new year to you too. :slight_smile:
I am sure about the segment tree solution.
But if you can check the fenwick tree one , it would be great.

hey @ma5termind if you can just give me C code to sort a multi-dimensional array of queries
Then i can test my solution in C.
1 5
2 4
3 5
i want these sorted as
2 4
1 5
3 5

@abeyaar, in order to sort the queries, you can store the queries in a vector of pairs… if you sort a vector using the STL sort function, it gets sorted first according to the first elements in the pairs, then accordin to the second element of the pair, since this is the default definition of the comparision function of pair…

hey i ain’t that comfortable with C++, i have no experience with STL and all that.
So if you can give me code in C,it would be of help

dude can you modify your code to get the queries sorted by Y? And not by X as i have given above…

you just have to assign y to v[i].F.F and x to v[i].F.S … rest will be the same…