#C8074. Employee Shift Overwork Determination

    ID: 52016 Type: Default 1000ms 256MiB

Employee Shift Overwork Determination

Employee Shift Overwork Determination

You are given N employees and a limit K which represents the maximum number of consecutive working days an employee is allowed to work. Initially, every employee has no assigned shifts.

You will then be given Q queries. Each query assigns a shift to an employee. A query is provided in the format: E S T, where E is the employee number, and S and T (with S ≤ T) represent the starting and ending day (inclusive) of the shift, respectively.

After adding a new shift, the employee's total working days are determined by merging all overlapping or adjacent shifts. Two shifts are considered adjacent if the end day of one is exactly one less than the start day of the next. Formally, if an employee ends up with one or more merged intervals, for any merged interval with starting day Smerged and ending day Tmerged, the condition for being within the allowed limit is:

$T_{merged} - S_{merged} + 1 \le K$

If the condition is violated in any merged interval after processing a query, or if the shift in the query itself has a duration more than K days, the output for that query is NO; otherwise, the output is YES.

Process all queries sequentially and output the result for each query.

inputFormat

The first line of input contains three integers N, K, and Q, separated by spaces.

Each of the following Q lines contains three integers: E S T, representing a query. E (1-indexed) is the employee number, and S and T (with S ≤ T) denote the starting and ending days of the shift, respectively.

outputFormat

For each query, output a single line containing either YES or NO. The result for each query should be printed in the order the queries are processed.

## sample
2 3 2
1 1 3
1 4 5
YES

NO

</p>