Grass Segments
Bessie is planting some grass on the positive real line. She has N (2≤N≤2⋅105) different cultivars of grass, and will plant the ith cultivar on the interval [ℓi,ri] (0<ℓi<ri≤109).
In addition, cultivar i grows better when there is some cultivar j (j=i) such that cultivar j and cultivar i overlap with length at least ki (0<ki≤ri−ℓi). Bessie wants to evaluate all of her cultivars. For each i, compute the number of j=i such that j and i overlap with length at least ki.
The overlaps of the cultivars is [4,6], which has length 2, which is at least 2 but not at least 3.
SCORING:
- Input 4-5: N≤5000
- Inputs 6-11: k is the same for all intervals
- Inputs 12-20: No additional constraints.
In addition, for Inputs 5, 7, ..., 19, ri≤2N for all i.
Problem credits: Benjamin Qi
Source: USA Computing Olympiad.
Input Format
The first line contains N.
The next N lines each contain three space-separated integers ℓi, ri, and ki.
Output Format
The answers for all cultivars on separate lines.