• + 0 comments

    It seems that C++ is fast enough for an O(Q(N+1000)) solution. Since the number of books is limited to 1000, counting sort is applicable. If the queried range was close to N each time, it would probably not pass the time limit (worst case ~10^8 operations), but it does pass for the given test cases.