I cant understand the bool b[100005]={false}; statement.
I tried searching this on google. And I got a whole lot of programs which use the 100005. What is that number? Why is it used? And what does the statement do?
Also what is the while(t--)? How can a quantity such as 't', ever be false?
There is subtask 3 in site you provided. In this subtask there may be maximum 100000 apple trees. So bool[100000] is enough. IMHO author writes 100005 on a safe side.