P29083 [洛谷] [CSGRound3] Red Envelope
普及
题目描述

Background

Wishing everyone a happy Year of the Rat! Best wishes!

May the pneumonia outbreak be controlled soon. Go China!

As the New Year arrives, Xiao Z always receives a lot of red envelopes (money given as a gift during the Chinese New Year).

Xiao Z is an avid player who loves to spend money on skins and stones, so he often spends part of his red envelope money.

However, Xiao Z is also very worried that his money will be spent within a few days. For this reason, Xiao Z has a sealing technique that can temporarily seal part of his money (making it unspendable), until it is unsealed on a certain day.

Problem Description

There are a total of $m$ events, and the events are divided into the following $3$ types:

  1. Xiao Z receives $a$ yuan in red envelope money.
  2. Xiao Z spends $a$ yuan on skins.
  3. Xiao Z seals $a$ yuan, which can only be unsealed one second before the $b$-th event occurs, and it is guaranteed that Xiao Z's current money is always greater than or equal to the sealed money.

When Xiao Z's money is insufficient for a certain event, he will feel unhappy, and he will not spend money if it is not enough.

Please tell Xiao Z how many events his money will be insufficient for.

Input Format

The first line contains an integer $m$, representing the total number of events.

The next $m$ lines, the first integer $t$ indicates the type of the event.

If $t=1$ or $t=2$, the next integer is $a$.

If $t=3$, the next two integers are $a$ and $b$.

Output Format

A single line containing an integer, representing the number of events where the money is insufficient.

Sample Input and Output

Sample Input #1

3
1 10
2 20
2 10

Sample Output #1

1

Sample Input #2

5
1 10
3 5 5
2 10
1 10
2 20

Sample Output #2

1

Notes

[Sample 1 Explanation]

Day 1: Receives $10$ yuan, balance $10$ yuan.

Day 2: Insufficient to spend $20$ yuan, balance $10$ yuan.

Day 3: Spends $10$ yuan, balance $0$ yuan.

Total: $1$ day.

[Sample 2 Explanation]

Day 1: Receives $10$ yuan, balance $10$ yuan.

Day 2: Seals $5$ yuan, balance $5$ yuan.

Day 3: Insufficient to spend $10$ yuan, balance $5$ yuan.

Day 4: Receives $10$ yuan, balance $15$ yuan.

Day 5: Unseals, spends $20$ yuan, balance $0$ yuan.

Total: $1$ day.


[Data Range]

For $50\%$ of the data, $m, a \leq 5 \times 10^3$.

For $70\%$ of the data, $t \ne 3$.

For $100\%$ of the data, $1 \leq b \leq m \leq 10^6$, $1 \leq t \leq 3$, $1 \leq a \leq 10^7$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 10 2 20 2 10
样例输出
1