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

A × B (HARD)

Back to problem

Editorial

Maintain whether each slot currently contains a value and, when it does, the value itself.

Use a segment tree whose node stores both the minimum and maximum value in its interval. An interval containing no value is represented by a separate empty state. When merging two nodes, return the nonempty node if exactly one side is empty. If both are nonempty, store the smaller minimum and the larger maximum.

A type 1 query changes one leaf to a present value. A type 3 query changes one leaf to the empty state. A type 2 query merges the nodes covering the requested interval. Print nothing if the result is empty; otherwise print the product of its minimum and maximum.

Since each value has absolute value at most 10910^9109, the product can reach 101810^{18}1018, so a 64-bit integer type is required.

The time complexity per test case is O((N+M)log⁡N)O((N+M)\log N)O((N+M)logN), and the space complexity is O(N)O(N)O(N).

Solution written by GPT5.6