AtCoder Beginner Contest 471
D
充电器
Chargers
AtCoder
⌀ 570
原题
← BE →

充电器AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is a charger with an unlimited number of charging slots. At time $0$, all slots are empty.

有一个充电器,拥有无限多的充电槽。在时刻 $0$,所有充电槽均为空。AI (CI翻译)

The maximum capacity of a battery is $V$. While a battery is plugged into a slot, it is charged at a rate of $1$ until its charge level reaches the maximum capacity (that is, the charge level increases by $1$ for every $1$ unit of time that passes).

电池的最大容量为 $V$。电池插入充电槽后,会以速率 $1$ 充电,直到电量达到最大容量(即经过 $1$ 单位时间,电量增加 $1$)。AI (CI翻译)

Process $Q$ queries in order. The $q$-th query is given in one of the following formats. Here, it is guaranteed that $t_1 < \dots < t_Q$.

请按顺序处理 $Q$ 个查询。第 $q$ 个查询的格式如下。保证 $t_1 < \dots < t_Q$。AI (CI翻译)

  • Type $1$ ($1\ t_q\ w_q$): At time $t_q$, plug one battery with charge level $w_q$ into a slot.
  • Type $2$ ($2\ t_q$): At time $t_q$, unplug one battery with the highest charge level from its slot, and output that battery's charge level. If there is no battery plugged into any slot, output $-1$ instead.
  • 类型 $1$(1\ t_q\ w_q):在时刻 $t_q$,将一块电量为 $w_q$ 的电池插入充电槽。
  • 类型 $2$(2\ t_q):在时刻 $t_q$,将当前电量最高的电池从其充电槽中取出,并输出该电池的电量。如果没有电池插在任何充电槽中,则输出 $-1$。
AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq Q \leq 3 \times 10^5$
  • $1 \leq V \leq 10^9$
  • For type $1$ queries, $1 \leq t_q \leq 10^9$.
  • For type $1$ queries, $0 \leq w_q \leq V$.
  • For type $2$ queries, $1 \leq t_q \leq 10^9$.
  • $t_1 < \dots < t_Q$
  • The input values are all integers.
  • $1 \leq Q \leq 3 \times 10^5$
  • $1 \leq V \leq 10^9$
  • 对于类型 $1$ 的查询,$1 \leq t_q \leq 10^9$。
  • 对于类型 $1$ 的查询,$0 \leq w_q \leq V$。
  • 对于类型 $2$ 的查询,$1 \leq t_q \leq 10^9$。
  • $t_1 < \dots < t_Q$
  • 输入中的所有数值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

Q V
\mathrm{query}_1
\vdots
\mathrm{query}_Q

Q V
\mathrm{query}_1
\vdots
\mathrm{query}_Q
AI (CI翻译)

Here, $\mathrm{query}_q$ represents the $q$-th query, and is given in one of the following two formats:

其中,$\mathrm{query}_q$ 表示第 $q$ 个查询,格式为以下两种之一:AI (CI翻译)

1 t_q w_q

1 t_q w_q
AI (CI翻译)

2 t_q

2 t_q
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Let $x$ be the number of type $2$ queries. Output $x$ lines.

设类型 $2$ 的查询数量为 $x$。输出 $x$ 行。AI (CI翻译)

The $k$-th line ($1 \leq k \leq x$) should contain the value to be outputed for the $k$-th type $2$ query.

第 $k$ 行($1 \leq k \leq x$)应包含第 $k$ 个类型 $2$ 查询的输出值。AI (CI翻译)

样例

Input #1
7 100
1 15 60
1 25 80
2 30
1 45 0
2 60
2 70
2 80
Output #1
85
100
25
-1
The seven queries are processed in the following order. - At time $15$, a battery with charge level $60$ is plugged in. At this point, the charger has a battery with charge level $60$. - At time $25$, a battery with charge level $80$ is plugged in. At this point, the charger has batteries with charge levels $70, 80$. - At time $30$, the charger has batteries with charge levels $75, 85$. Of these, the battery with charge level $85$ is unplugged. - At time $45$, a battery with charge level $0$ is plugged in. At this point, the charger has batteries with charge levels $0, 90$. - At time $60$, the charger has batteries with charge levels $15, 100$. Of these, the battery with charge level $100$ is unplugged. - At time $70$, the charger has a battery with charge level $25$. This battery, with charge level $25$, is unplugged. - At time $80$, no battery is plugged into the charger. Thus, no battery is unplugged.
Input #2
20 380736236
1 21873985 256702097
2 86369729
1 114301317 288304981
1 147244640 305840435
2 150951976
1 331581391 50335458
1 352989552 47577202
1 400130024 345362760
2 458793150
2 509082216
1 591375600 197371572
1 617022014 101276068
1 679649471 310249627
1 796351653 268586022
1 825648347 129608152
2 908069704
2 921770319
1 949684819 372272469
1 971850999 335461408
2 986253026
Output #2
321197841
324955640
380736236
380736236
380736236
380736236
380736236
题目信息
题号
abc471_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。