PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000109. Bảo trì tàu hỏa (Train Maintenance)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bảo trì tàu hỏa (Train Maintenance)

Train Maintenance

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A depot has nn train models, numbered 11 to nn. At any time there is at most one train of each model in the depot. Initially the depot is empty.

Model ii has two positive integers xix_i and yiy_i. If a train of model ii is added on day tt, it repeatedly follows this schedule:

  • It works for xix_i consecutive days, including day tt.
  • It undergoes maintenance for yiy_i consecutive days.
  • It works for another xix_i days, then undergoes another yiy_i maintenance days, and so on until it is removed.

There are mm days numbered from 11 to mm. Exactly one operation occurs at the beginning of each day:

  • 1 k: Add one train of model kk. Its working/maintenance schedule starts on the current day.
  • 2 k: Remove the train of model kk. 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 n,mn,m.
  • Each of the following nn lines contains xi,yix_i,y_i for model ii.
  • Each of the next mm lines contains op k, describing the operation at the beginning of day tt. op is either 1 or 2.

Output

Print mm lines. The tt-th line contains the number of trains under maintenance on day tt, after that day's operation.

Subtasks

  • Subtask 1 (15 points): 1≤n≤601\le n\le 60; 1≤m≤601\le m\le 60; 1≤xi,yi≤1091\le x_i,y_i\le 10^9 for all 1≤i≤n1\le i\le n; every operation has op in {1,2}\{1,2\} and 1≤k≤n1\le k\le n; each model has at most one train at any time and all operations are valid.
  • Subtask 2 (20 points): 1≤n≤2 0001\le n\le 2\,000; 1≤m≤2 0001\le m\le 2\,000; 1≤xi,yi≤1091\le x_i,y_i\le 10^9 for all 1≤i≤n1\le i\le n; every operation has op in {1,2}\{1,2\} and 1≤k≤n1\le k\le n; each model has at most one train at any time and all operations are valid.
  • Subtask 3 (25 points): 1≤n≤20 0001\le n\le 20\,000; 1≤m≤20 0001\le m\le 20\,000; 1≤xi,yi≤1091\le x_i,y_i\le 10^9 for all 1≤i≤n1\le i\le n; every operation has op in {1,2}\{1,2\} and 1≤k≤n1\le k\le n; each model has at most one train at any time and all operations are valid.
  • Subtask 4 (40 points): 1≤n≤200 0001\le n\le 200\,000; 1≤m≤200 0001\le m\le 200\,000; 1≤xi,yi≤1091\le x_i,y_i\le 10^9 for all 1≤i≤n1\le i\le n; every operation has op in {1,2}\{1,2\} and 1≤k≤n1\le k\le n; 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 33 is added and works, so the answer is 00. On day 2, train 11 is added; train 33 finished its one working day and is in maintenance, so the answer is 11. On day 3, train 11 is removed, and train 33 has already returned to work, so the answer is 00. On day 4, train 33 is removed; the depot is empty, so the answer is 00.

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 55 with x5=1,y5=2x_5=1,y_5=2; it is working. On day 2 the train is removed before counting, so the answer is zero. Day 3 adds model 55 again, restarting its schedule; it is working. Day 4 adds model 11; train 55 has reached its first maintenance day while train 11 is still working. Thus the answer is 11.