#C3424. Count Overlapping Tasks

    ID: 46850 Type: Default 1000ms 256MiB

Count Overlapping Tasks

Count Overlapping Tasks

You are given the operational time interval of a defective component, represented by two integers \(t_s\) and \(t_e\) (with \(t_s \leq t_e\)), and a list of tasks. Each task is described by its start time and end time. A task is said to overlap with the defective component if the task and the component share at least one common time unit, i.e. their intervals intersect.

Your task is to count the number of tasks that overlap with the defective component's operational time.

Note: Two intervals \([a, b]\) and \([c, d]\) overlap if and only if they satisfy the condition:

[ \neg (b < t_s ;\text{or}; a > t_e) ]

Input is read from stdin and output should be printed to stdout.

inputFormat

The input consists of multiple lines:

  • The first line contains two space-separated integers \(t_s\) and \(t_e\) representing the start and end times of the defective component.
  • The second line contains an integer \(n\) representing the number of tasks.
  • Each of the following \(n\) lines contains two space-separated integers representing the start and end times of a task.

You can assume that all integers are within a reasonable range and \(t_s \leq t_e\).

outputFormat

Output a single integer representing the number of tasks that overlap with the defective component's interval.

## sample
5 10
4
2 6
8 12
1 4
9 15
3