Watering Pots

easyPrefix SumGreedy

There are $$$n$$$ flower pots in a row, numbered from $$$1$$$ to $$$n$$$. Each of the $$$k$$$ visitors waters all pots in a given inclusive range $$$[l_i, r_i]$$$ once.

Compute how many times each pot is watered after all visitors.

Input Format:

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n, k \leq 10^5$$$).

The next $$$k$$$ lines each contain two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$), describing the range watered by the $$$i$$$-th visitor.

Output Format:

Print $$$n$$$ integers. The $$$i$$$-th integer should be the total number of times pot $$$i$$$ is watered.

Examples:

Example 1:

Input:

10 8
1 10
2 2
3 3
4 4
5 5
6 6
7 7
8 8

Output:

1 2 2 2 2 2 2 2 1 1

Code

Loading Editor...