A15609 | Magician and Pigs (Hard Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is the hard version of the problem. The only difference between the two versions is the constraint on $n$ and $x$ . You can make hacks only if both versions of the problem are solved.
Little09 has been interested in magic for a long time, and it's so lucky that he meets a magician! The magician will perform $n$ operations, each of them is one of the following three:
- $1\ x$ : Create a pig with $x$ Health Points.
- $2\ x$ : Reduce the Health Point of all living pigs by $x$ .
- $3$ : Repeat all previous operations. Formally, assuming that this is the $i$ -th operation in the operation sequence, perform the first $i-1$ operations (including "Repeat" operations involved) in turn.
A pig will die when its Health Point is less than or equal to $0$ .
Little09 wants to know how many living pigs there are after all the operations. Please, print the answer modulo $998\,244\,353$ .
Little09 has been interested in magic for a long time, and it's so lucky that he meets a magician! The magician will perform $n$ operations, each of them is one of the following three:
- $1\ x$ : Create a pig with $x$ Health Points.
- $2\ x$ : Reduce the Health Point of all living pigs by $x$ .
- $3$ : Repeat all previous operations. Formally, assuming that this is the $i$ -th operation in the operation sequence, perform the first $i-1$ operations (including "Repeat" operations involved) in turn.
A pig will die when its Health Point is less than or equal to $0$ .
Little09 wants to know how many living pigs there are after all the operations. Please, print the answer modulo $998\,244\,353$ .
输入格式
The first line contains a single integer $n$ ( $1\leq n\leq 8\cdot 10^5$ ) — the number of operations.
Each of the following $n$ lines contains an operation given in the form described in the problem statement. It's guaranteed that $1\leq x\leq 10^9$ in operations of the first two types.
Each of the following $n$ lines contains an operation given in the form described in the problem statement. It's guaranteed that $1\leq x\leq 10^9$ in operations of the first two types.
输出格式
Print a single integer — the number of living pigs after all the operations, modulo $998\,244\,353$ .
输入输出样例
输入 #1
4 1 8 2 3 3 3
输出 #1
2
输入 #2
6 1 5 1 6 2 2 3 1 4 3
输出 #2
5
输入 #3
12 2 1 1 15 1 9 3 1 12 2 2 1 13 3 2 1 1 9 1 8 3
输出 #3
17
In the first example, the operations are equivalent to repeating four times: create a pig with $8$ Health Points and then reduce the Health Points of all living pigs by $3$ . It is easy to find that there are two living pigs in the end with $2$ and $5$ Health Points.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted