A13742 | Two Types of Spells
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.
There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell can be cast only once per battle, but Polycarp can cast them in any order.
For example, suppose that Polycarp knows three spells: a fire spell of power $5$ , a lightning spell of power $1$ , and a lightning spell of power $8$ . There are $6$ ways to choose the order in which he casts the spells:
- first, second, third. This order deals $5 + 1 + 2 \cdot 8 = 22$ damage;
- first, third, second. This order deals $5 + 8 + 2 \cdot 1 = 15$ damage;
- second, first, third. This order deals $1 + 2 \cdot 5 + 8 = 19$ damage;
- second, third, first. This order deals $1 + 2 \cdot 8 + 2 \cdot 5 = 27$ damage;
- third, first, second. This order deals $8 + 2 \cdot 5 + 1 = 19$ damage;
- third, second, first. This order deals $8 + 2 \cdot 1 + 2 \cdot 5 = 20$ damage.
Initially, Polycarp knows $0$ spells. His spell set changes $n$ times, each time he either learns a new spell or forgets an already known one. After each change, calculate the maximum possible damage Polycarp may deal using the spells he knows.
There are two types of spells: fire spell of power $x$ deals $x$ damage to the monster, and lightning spell of power $y$ deals $y$ damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell can be cast only once per battle, but Polycarp can cast them in any order.
For example, suppose that Polycarp knows three spells: a fire spell of power $5$ , a lightning spell of power $1$ , and a lightning spell of power $8$ . There are $6$ ways to choose the order in which he casts the spells:
- first, second, third. This order deals $5 + 1 + 2 \cdot 8 = 22$ damage;
- first, third, second. This order deals $5 + 8 + 2 \cdot 1 = 15$ damage;
- second, first, third. This order deals $1 + 2 \cdot 5 + 8 = 19$ damage;
- second, third, first. This order deals $1 + 2 \cdot 8 + 2 \cdot 5 = 27$ damage;
- third, first, second. This order deals $8 + 2 \cdot 5 + 1 = 19$ damage;
- third, second, first. This order deals $8 + 2 \cdot 1 + 2 \cdot 5 = 20$ damage.
Initially, Polycarp knows $0$ spells. His spell set changes $n$ times, each time he either learns a new spell or forgets an already known one. After each change, calculate the maximum possible damage Polycarp may deal using the spells he knows.
输入格式
The first line contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of changes to the spell set.
Each of the next $n$ lines contains two integers $tp$ and $d$ ( $0 \le tp_i \le 1$ ; $-10^9 \le d \le 10^9$ ; $d_i \neq 0$ ) — the description of the change. If $tp_i$ if equal to $0$ , then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.
If $d_i > 0$ , then Polycarp learns a spell of power $d_i$ . Otherwise, Polycarp forgets a spell with power $-d_i$ , and it is guaranteed that he knew that spell before the change.
It is guaranteed that the powers of all spells Polycarp knows after each change are different (Polycarp never knows two spells with the same power).
Each of the next $n$ lines contains two integers $tp$ and $d$ ( $0 \le tp_i \le 1$ ; $-10^9 \le d \le 10^9$ ; $d_i \neq 0$ ) — the description of the change. If $tp_i$ if equal to $0$ , then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.
If $d_i > 0$ , then Polycarp learns a spell of power $d_i$ . Otherwise, Polycarp forgets a spell with power $-d_i$ , and it is guaranteed that he knew that spell before the change.
It is guaranteed that the powers of all spells Polycarp knows after each change are different (Polycarp never knows two spells with the same power).
输出格式
After each change, print the maximum damage Polycarp can deal with his current set of spells.
输入输出样例
输入 #1
6 1 5 0 10 1 -5 0 5 1 11 0 -10
输出 #1
5 25 10 15 36 21
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted