#ABC471D. 充电器 / Chargers

    ID: 19553 传统题 2000ms 256MiB 尝试: 65 已通过: 34 显示难度普及+/提高− 上传者: 标签>AtCoder数据结构堆(优先队列)

充电器 / Chargers

Problem Statement

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

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

Process QQ queries in order. The qq-th query is given in one of the following formats. Here, it is guaranteed that t1<<tQt_1 < \dots < t_Q.

  • Type 11 (1 tq wq1\ t_q\ w_q): At time tqt_q, plug one battery with charge level wqw_q into a slot.
  • Type 22 (2 tq2\ t_q): At time tqt_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-1 instead.

Constraints

  • 1Q3×1051 \leq Q \leq 3 \times 10^5
  • 1V1091 \leq V \leq 10^9
  • For type 11 queries, 1tq1091 \leq t_q \leq 10^9.
  • For type 11 queries, 0wqV0 \leq w_q \leq V.
  • For type 22 queries, 1tq1091 \leq t_q \leq 10^9.
  • t1<<tQt_1 < \dots < t_Q
  • The input values are all integers.

Input

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

  • QQ VV
  • query1\mathrm{query}_1
  • \vdots
  • queryQ\mathrm{query}_Q

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

  • 11 tqt_q wqw_q

or

  • 22 tqt_q

Output

Let xx be the number of type 22 queries. Output xx lines.

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

7 100
1 15 60
1 25 80
2 30
1 45 0
2 60
2 70
2 80
85
100
25
-1

The seven queries are processed in the following order.

  • At time 1515, a battery with charge level 6060 is plugged in. At this point, the charger has a battery with charge level 6060.
  • At time 2525, a battery with charge level 8080 is plugged in. At this point, the charger has batteries with charge levels 70,8070, 80.
  • At time 3030, the charger has batteries with charge levels 75,8575, 85. Of these, the battery with charge level 8585 is unplugged.
  • At time 4545, a battery with charge level 00 is plugged in. At this point, the charger has batteries with charge levels 0,900, 90.
  • At time 6060, the charger has batteries with charge levels 15,10015, 100. Of these, the battery with charge level 100100 is unplugged.
  • At time 7070, the charger has a battery with charge level 2525. This battery, with charge level 2525, is unplugged.
  • At time 8080, no battery is plugged into the charger. Thus, no battery is unplugged.
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
321197841
324955640
380736236
380736236
380736236
380736236
380736236