DOJ logoDOJ
Problems
Recently added problemsSaved problems
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Daeshin High School and Queries

Back to problem

Editorial

Store every discomfort value directly in a 4×N4 \times N4×N 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 O(1)O(1)O(1) time.

For a type 2 query, scan the requested floor from classroom 111 through classroom NNN. 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 111 through 444, and classrooms 111 through NNN 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 O(QN)O(QN)O(QN), and the space complexity is O(N)O(N)O(N).

Solution written by GPT5.6