QOJ.ac

QOJ

时间限制: 3 s 内存限制: 2048 MB 总分: 100

#5399. King Kog 的接待处

统计

Kog 国王对骑士们随意的作风感到厌烦——他们总是毫无预兆地闯入大厅!因此,国王决定建立一个接待处,并设置一个队列。每位骑士需要提前选择到达时间以及访问时长。骑士们按照记录的时间顺序接受接待,但每位骑士都必须等待在他之前的所有骑士完成访问。

Keabeanie 公主想见她的父亲。然而,她不想打扰骑士们,所以她也加入了队列。不幸的是,骑士们经常改变主意——他们可能会加入队列或取消访问。请帮助公主计算,如果她在给定的时间点加入队列,她需要等待多久才能见到她的父亲。

输入格式

输入的第一行包含一个整数 $q$ ($1 \le q \le 3 \cdot 10^5$),表示事件的数量。事件共有三种类型:加入、取消或查询。

  • 加入 “+ $t$ $d$” ($1 \le t, d \le 10^6$) —— 一位新骑士加入队列,$t$ 是骑士到达的时间,$d$ 是访问的持续时间。
  • 取消 “- $i$” ($1 \le i \le q$) —— 骑士取消访问,其中 $i$ 是所有事件列表中对应的加入事件的编号(从 1 开始计数)。
  • 查询 “? $t$” ($1 \le t \le 10^6$) —— Keabeanie 询问如果她在时间 $t$ 到达,她需要等待多久。

保证在每次事件后,队列中不会有两名骑士的到达时间相同。取消事件指向的是之前尚未被取消的加入事件。

Keabeanie 可以在某位骑士到达的同一时间到达,但 Keabeanie 非常有礼貌,她会等待该骑士先通过。

输出格式

对于每个查询,输出一行,表示 Keabeanie 需要等待的时间。

样例

输入 1

19
? 3
+ 2 2
? 3
? 4
+ 5 2
? 5
? 6
+ 1 2
? 2
? 3
? 4
? 5
? 6
? 7
? 9
- 8
? 2
? 3
? 6

输出 1

0
1
0
2
1
3
2
1
2
1
0
0
2
1
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.