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

#FT0000117. Thông báo chưa đọc của Thor (Thor)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Thông báo chưa đọc của Thor (Thor)

Thor

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Thor has nn phone applications. Every newly created notification gets a global creation number, starting at 11, regardless of its application. Initially there are no notifications.

Process qq events in chronological order:

  • 1 x: application xx creates one new unread notification.
  • 2 x: mark all notifications created so far by application xx as read. Future notifications remain unread until read.
  • 3 t: mark the globally first tt created notifications as read, not the first tt currently unread notifications. Already-read notifications may be read again.

After every event output the total number of unread notifications. Reading never deletes a notification.

Input

  • First line: two integers n,qn,q (applications and events).
  • Next qq lines: an event 1 x, 2 x, or 3 t in chronological order.
  • For every type 3, at least tt notifications have been created so far.

Output

Print exactly qq lines: the unread notification count after each event.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20, 1≤q≤401\le q\le 40; for type 1 and 2, 1≤x≤n1\le x\le n; for type 3, 1≤t≤1\le t\le the number of type 1 events so far.
  • Subtask 2 (30 points): 1≤n≤2001\le n\le 200, 1≤q≤34001\le q\le 3400; for type 1 and 2, 1≤x≤n1\le x\le n; for type 3, 1≤t≤1\le t\le the number of type 1 events so far.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000, 1≤q≤3000001\le q\le 300000; for type 1 and 2, 1≤x≤n1\le x\le n; for type 3, 1≤t≤1\le t\le the number of type 1 events so far.

Examples

Example 1

Input

3 4
1 3
1 1
1 2
2 3

Output

1
2
3
2

Explanation

  • Event 1, 1 3: new notification #1 from app 3; unread = 1.
  • Event 2, 1 1: new notification #2 from app 1; unread = 2.
  • Event 3, 1 2: new notification #3 from app 2; unread = 3.
  • Event 4, 2 3: mark all existing notifications of app 3 as read; unread = 2.

Example 2

Input

4 8
1 2
1 4
2 2
1 2
3 2
1 3
2 4
3 4

Output

1
2
1
2
1
2
2
0

Explanation

  • Event 1, 1 2: new notification #1 from app 2; unread = 1.
  • Event 2, 1 4: new notification #2 from app 4; unread = 2.
  • Event 3, 2 2: mark all existing notifications of app 2 as read; unread = 1.
  • Event 4, 1 2: new notification #3 from app 2; unread = 2.
  • Event 5, 3 2: mark global notifications 1 through 2 as read; unread = 1.
  • Event 6, 1 3: new notification #4 from app 3; unread = 2.
  • Event 7, 2 4: mark all existing notifications of app 4 as read; unread = 2.
  • Event 8, 3 4: mark global notifications 1 through 4 as read; unread = 0.