Convoluted Intervals
Time limit2sMemory limit1024 MB
Count, for every k from 0 to 2M, how many ordered pairs of intervals have a_i + a_j <= k <= b_i + b_j.
- Level
Medium7 of 10
- Topics
- Prefix sum, Combinatorics, Array, Math
- Solved
- No attempts yet
Problem
The cows are hard at work trying to invent interesting new games to play. One of their current endeavors involves a set of intervals (), where the th interval starts at position on the number line and ends at position . Both and are integers in the range , where .
To play the game, Bessie chooses some interval (say, the th interval) and her cousin Elsie chooses some interval (say, the th interval, possibly the same as Bessie's interval). Given some value , they win if .
For every value of in the range , please count the number of ordered pairs for which Bessie and Elsie can win the game.
Input
The first line of input contains and . Each of the next lines describes an interval in terms of integers and .
Output
Please print lines as output, one for each value of in the range .