#P15100. [ICPC 2025 LAC] Festival Signs

[ICPC 2025 LAC] Festival Signs

题目描述

During a festival, advertisement signs are added to and removed from a stage at different moments. Each sign has a rectangular shape and is placed perpendicular to the ground, with one side resting firmly on the ground.

A webcam is livestreaming the festival, showing a 2D image of the stage. In this image, the bottom border corresponds to the ground. Each sign covers a rectangular area in the image. A sign is described by an interval [A,B][A, B] and a height HH, meaning it covers all points (x,y)(x, y) of the image where AxBA \le x \le B and 0y<H0 \le y < H.

Note that the sign covers the points on the bottom and side borders of the rectangle, but not the top border. Besides, rectangles representing different signs may overlap.

During the livestream, the manager will make several queries at different moments. Each query specifies an interval [L,R][L, R], and asks for the minimum height y0y \ge 0 among all uncovered points (x,y)(x, y) with LxRL \le x \le R, with xx and yy being real numbers.

Your task is to write a program to process a sequence of NN events: sign additions, sign removals, and queries about the minimum uncovered height over a given interval.

As an example, consider the following sequence of N=7N = 7 events given in chronological order (see picture below):

  • Sign with [A,B]=[2,5][A, B] = [2, 5] and H=3H = 3 is added.
  • Sign with [A,B]=[4,7][A, B] = [4, 7] and H=5H = 5 is added.
  • Query [1,10][1, 10] is made. The answer to this query is 00. An uncovered point with minimum height within the interval is, for instance, the point with coordinates (1.5,0)(1.5, 0).
  • Query [2,7][2, 7] is made, with answer 33.
  • Query [4,5][4, 5] is made, with answer 55.
  • Second added sign is removed.
  • Query [4,5][4, 5] is made, with answer 33. Note that the removal of the second added sign changed the answer of query [4,5][4, 5].

:::align{center} :::

输入格式

The first line contains an integer NN (1N21051 \le N \le 2 \cdot 10^5) indicating the number of events.

Each of the next NN lines describes an event, in chronological order. The content of the line depends on the event, as follows:

  • Sign addition: the line contains the character “+” (plus sign) and three integers AA, BB and HH (1A,B,H1091 \le A, B, H \le 10^9 and A<BA < B), representing that a sign is added, covering a rectangle of the image as explained in the statement. Each added sign is assigned a sequential integer identifier, starting from 11.
  • Sign removal: the line contains the character “-” (minus sign) and an integer I1I \ge 1, indicating that the sign with identifier II is removed. It is guaranteed that II identifies an added and not previously removed sign.
  • Query: the line contains the character “?” (question mark) and two integers LL and RR (1L<R1091 \le L < R \le 10^9), asking for the minimum uncovered height within the interval [L,R][L, R], as explained in the statement. It is guaranteed that the input contains at least one query.

输出格式

Output a line for each query, with an integer indicating the minimum uncovered height within the corresponding interval.

7
+ 2 5 3
+ 4 7 5
? 1 10
? 2 7
? 4 5
- 2
? 4 5
0
3
5
3
4
+ 1 2 1
+ 3 4 1
? 1 2
? 1 4
1
0