SPOJ DQUERY TLE

fenwick
segment-tree
spoj

#1

i am getting TLE for both segment tree and BIT

Segment Tree solution
Fenwick Tree solution
Can anyone help??


#2

@abeyaar

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:


#3

@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…


#4

@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.


#5

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.
3
1 5
2 4
3 5
i want these sorted as
2 4
1 5
3 5


#6

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


#7

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


#8

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