PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000267. Chồng nhiều lịch học (Overlapping Class Schedules)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chồng nhiều lịch học (Overlapping Class Schedules)

Overlapping Class Schedules

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN classes. Class ii runs during the half-open interval [li,ri)[l_i,r_i). For each k=1,2,…,Nk=1,2,\ldots,N, compute the total duration with exactly kk active classes. Intervals may coincide; the length of [a,b)[a,b) is b−ab-a.

Input

First line: NN. Next NN lines: li,ril_i,r_i.

Output

Print NN integers D1,D2,…,DND_1,D_2,\ldots,D_N on one line, where DkD_k is the total duration with exactly kk active classes.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1001\le N\le 100; 0≤li<ri≤1000\le l_i<r_i\le 100.
  • Subtask 2 (30 points): 1≤N≤2000001\le N\le 200000; 0≤li<ri≤10120\le l_i<r_i\le 10^12; li=l1l_i=l_1.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 0≤li<ri≤10120\le l_i<r_i\le 10^12.

Example 1

Input

3
1 4
2 5
4 6

Output

2 3 0

Explanation

[1,2) and [5,6) have one class; [2,5) has two; none have three.

Example 2

Input

2
0 3
0 3

Output

0 3

Explanation

Both classes coincide for 3 time units.