#USACOC2213C. Convoluted Intervals

Convoluted Intervals

Description

The cows are hard at work trying to invent interesting new games to play. One oftheir current endeavors involves a set of NN intervals, where the ii-th interval starts at position aia_i onthe number line and ends at position biaib_i \geq a_i. Both aia_i and bib_i areintegers in the range 0M0 \ldots M, where 1M50001 \leq M \leq 5000.

To play the game, Bessie chooses some interval (say, the ii-th interval) and hercousin Elsie chooses some interval (say, the jj-th interval, possibly the sameas Bessie's interval). Given some value kk, they win if ai+ajkbi+bja_i + a_j \leq k \leq b_i + b_j.

For every value of kk in the range 02M0 \ldots 2M, please count the number ofordered pairs (i,j)(i,j) for which Bessie and Elsie can win the game.

  • 1N21051\le N\le 2\cdot 10^5

Input Format

The first line of input contains NN and MM. Each of the next NN lines describes an interval in terms of integers aia_i and bib_i.

Output Format

Please print 2M+12M+1 lines as output, one for each value of kk in the range 02M0 \ldots 2M.

2 5
1 3
2 5
2 5
1 3
2 5

Scoring

  • Test cases 1-2 satisfy N100,M100N\le 100, M\le 100.
  • Test cases 3-5 satisfy N5000N\le 5000.
  • Test cases 6-20 satisfy no additional constraints.

Note that output values might be too large to fit into a 32-bit integer, so youmay want to use 64-bit integers (e.g., long long ints in C or C++).

Problem Credit

Problem credits: Benjamin Qi