#1378
Diamond V
King Kog's Reception
시간 제한
3s
메모리 제한
512MB
제출
2
정답
1
맞힌 사람
1
정답 비율
50.0%

문제

King Kog got annoyed of the usual laxity of his knights — they can break into his hall without prior notice! Thus, the King decided to build a reception with a queue where each knight chooses in advance the time when he will come and how long the visit will take. The knights are served in the order of the recorded time, but each knight has to wait until the visits of all the knights before him are finished.

Princess Keabeanie wants to see her father. However, she does not want to interrupt the knights so she joins the queue. Unfortunately, the knights change their minds very often — they can join the queue or cancel their visits. Please help the princess to understand how long she will have to wait until she sees her father if she enters the queue at the specified moments of time given the records at the reception.

입력

The first line of the input contains a single integer qq (1q31051 \leq q \leq 3 \cdot 10^5) — the number of events. An event can be of three types: join, cancel, or query.

  • Join "+ $t$ $d$" (1t,d1061 \leq t, d \leq 10^6) — a new knight joins the queue, where tt is the time when the knight will come and dd is the duration of the visit.
  • Cancel "- $i$" (1iq1 \leq i \leq q) — the knight cancels the visit, where ii is the number (counted starting from one) of the corresponding join event in the list of all events.
  • Query "? $t$" (1t1061 \leq t \leq 10^6) — Keabeanie asks how long she will wait if she comes at the time tt.

It is guaranteed that after each event there are no two knights with the same entrance time in the queue. Cancel events refer to the previous joins that were not cancelled yet.

Keabeanie can come at the same time as some knight, but Keabeanie is very polite and she will wait for the knight to pass.

출력

For each query write a separate line with the amount of time Keabeanie will have to wait.

예제 입력 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
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
#순위사용자언어시간메모리코드 길이
8747🥇
조서현
C++141ms36352KB1723B
난이도 투표
Diamond V1명 투표· 2일 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
#사용자문제결과언어시간메모리코드 길이제출 시간
8747
맞았습니다
C++141ms36352KB1723B2026. 06. 04. 02:09
8746
틀렸습니다
C++--1720B2026. 06. 04. 02:07