Practice · 5 of 5
Painted Exactly Once
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** A fence of n planks gets q paint jobs, each covering [l, r]. Count
the planks painted **exactly once**.
**Input:** Line 1: n q (1 <= n, q <= 2*10^5). Next q lines: l r (1 <= l <= r <= n).
**Output:** One integer — planks with exactly one coat.
**Example:** 5 2 / 1 2 / 2 3 -> 2 (planks 1 and 3; plank 2 got two coats).
Press Submit to check your solution.
Back to lesson: Practice: Difference Array Problem Set