Go through the days in increasing order and decide, for each day, which exam to take on it. Greedy (earliest deadline first): among the exams that are not taken yet and whose window has already opened (l_i \le d, where is the current day), take the one with the smallest r_i. If this r_i < d, the answer is NO; if every exam gets a day, the answer is YES.
Why it is correct. Suppose some valid choice of days agrees with the greedy on all days before , and let be the exam picked on day . In that choice x_e \ge d: every earlier day holds another exam or was skipped when every remaining l_i was larger. Hence r_e \ge x_e \ge d, and the greedy does not answer NO on day . If day is free in that choice, move to day . If day belongs to another exam , swap them: goes to day , and goes to day x_e, which fits because l_f \le d < x_e \le r_e \le r_f (the greedy chose , so r_e \le r_f). Either way the choice stays valid and now agrees with the greedy on day too. By induction, whenever a valid choice exists, the greedy never answers NO; and if it answers YES, its own days are a valid choice.
Implementation. Sort the exams by l_i and keep the opened ones in a min-heap by r_i. Days go up to 10^9, so we do not walk over them one by one: when the heap is empty, jump the current day straight to the next l_i. Each step of the loop takes one exam out of the heap, so there are exactly steps.
The same criterion can be stated via Hall's theorem: the answer is YES if and only if every segment of days contains at most b - a + 1 whole windows [l_i, r_i]. The greedy checks this implicitly.
The complexity is O(n \log n) per test case.