#SRD0000109. Bảo trì tàu hỏa (Train Maintenance)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bảo trì tàu hỏa (Train Maintenance)
Train Maintenance
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A depot has train models, numbered to . At any time there is at most one train of each model in the depot. Initially the depot is empty.
Model has two positive integers and . If a train of model is added on day , it repeatedly follows this schedule:
- It works for consecutive days, including day .
- It undergoes maintenance for consecutive days.
- It works for another days, then undergoes another maintenance days, and so on until it is removed.
There are days numbered from to . Exactly one operation occurs at the beginning of each day:
1 k: Add one train of model . Its working/maintenance schedule starts on the current day.2 k: Remove the train of model . This train does not count as being under maintenance on its removal day.
Every operation is valid: an addition uses an absent model, and a removal uses a model currently present.
Task: After the operation at the beginning of every day, determine the number of trains under maintenance on that day. Working trains are not included.
Input
- The first line contains two integers .
- Each of the following lines contains for model .
- Each of the next lines contains
op k, describing the operation at the beginning of day .opis either1or2.
Output
Print lines. The -th line contains the number of trains under maintenance on day , after that day's operation.
Subtasks
- Subtask 1 (15 points): ; ; for all ; every operation has
opin and ; each model has at most one train at any time and all operations are valid. - Subtask 2 (20 points): ; ; for all ; every operation has
opin and ; each model has at most one train at any time and all operations are valid. - Subtask 3 (25 points): ; ; for all ; every operation has
opin and ; each model has at most one train at any time and all operations are valid. - Subtask 4 (40 points): ; ; for all ; every operation has
opin and ; each model has at most one train at any time and all operations are valid.
Examples
Example 1
Input
3 4
10 15
12 10
1 1
1 3
1 1
2 1
2 3
Output
0
1
0
0
Explanation
On day 1, train is added and works, so the answer is . On day 2, train is added; train finished its one working day and is in maintenance, so the answer is . On day 3, train is removed, and train has already returned to work, so the answer is . On day 4, train is removed; the depot is empty, so the answer is .
Example 2
Input
5 4
1 1
10000000 100000000
998244353 1
2 1
1 2
1 5
2 5
1 5
1 1
Output
0
0
0
1
Explanation
Day 1 adds train with ; it is working. On day 2 the train is removed before counting, so the answer is zero. Day 3 adds model again, restarting its schedule; it is working. Day 4 adds model ; train has reached its first maintenance day while train is still working. Thus the answer is .