Editorial
Store every discomfort value directly in a array.
For a type 1 query, inspect the construction position and its four neighbors. Increase only the positions that lie inside the building. Since at most five positions are inspected, one update takes time.
For a type 2 query, scan the requested floor from classroom through classroom . Update the answer only when a strictly larger discomfort value is found. This automatically chooses the smallest classroom number in case of a tie.
After all queries, scan floors through , and classrooms through within each floor. Again, update the answer only for a strictly larger value. The required tie-breaking order is then satisfied automatically.
The time complexity is , and the space complexity is .
Solution written by GPT5.6