check constraints, N can go upto 10^5 but you just took an array of 10^4+1. And from your code what i can see is, you are checking whether frog-A can send message to frog-B or not for each query. I haven’t tried this but I think you will get TLE because queries can also go upto 10^5.
Not Actually Mistake but:
- In sort function i don’t think you need to do
+0
-
long long
will be always enough, though preferint64_t
if you are usingcin
andcout
My Solution : CodeChef: Practical coding for everyone