BGSHOOT - Shoot and kill
The problem is about Mr.BG who is a great hunter. Today he has gone to a dense forest for hunting and killing animals.
Sadly, he has only one bullet in his gun. He wants to kill as many animals as possible with only one bullet.
He has already known the information of duration availability of all animals of the forest.
So, he is planning to shoot at a time so that he could kill maximum animal.
Input begins with an integer N denoting total numbers of animals.
Next N lines contains the duration of availability of animal denoting by X (Starting time) and Y (Ending time) .
Then, there will be Q, denoting the total numbers of queries to be answer.
Each query giving two integer L and R, L denoting the time hunter will come to forest and begins shooting
and R denoting last time upto which he will stay at forest for hunting.
For each query output an integer denoting maximum numbers of animals he could kill by shooting at a time during L and R (inclusive).
Input: 4 1 2 2 3 4 5 6 7 4 1 5 2 3 4 7 5 7 Output: 2 2 1 1
coordinate compression + segtree works just fine, there's no need for lazy, you can just keep track of how many animals are alive at the ith momentLast edit: 2018-05-11 17:30:48
if u are beginner then need solution??? ha ha!!!!!!!!!! so,first search co-ordinate compression in google and then take pen and paper then choose DS then solve it
Nice problem....learnt new thing!:) lazy+seg tree+compression
segment tree, lazy propagation,path compression :)
Awesome Problem.. BIT+segment tree+path compression.. Everything in one qstn..
1st query - the maximum no. of animal will be killed at time =2 output = 2(1 2 and 2 3)
If you had read carefully there is a line "by shooting at a time"....So, question is asking maximum number of segment that could be hit by any one of point from L to R. Hope it helps.
is the output correct?
somebody elaborate output please