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

Baseball Fans

Back to problem

Editorial

First, find one representative fan for each team.

Consider querying the set of people from 111 to iii. If the return value increases compared to the previous prefix, then person iii supports a team that has not appeared before. We record person iii as a representative of that team.

After this process, we have exactly one representative for every team, and all representatives support different teams.

Now consider an unclassified person ppp. Take a subset SSS of the representatives and query SSS together with ppp. Since all representatives support distinct teams, the number of distinct teams among the representatives in SSS is exactly ∣S∣|S|∣S∣.

  • If the return value is ∣S∣|S|∣S∣, then SSS contains the representative of ppp's team.
  • If the return value is ∣S∣+1|S|+1∣S∣+1, then SSS does not contain the representative of 's team.

Therefore, we can binary search over the representatives to determine which representative supports the same team as ppp.

Finding the representatives uses NNN queries, and classifying each person uses O(log⁡N)O(\log N)O(logN) queries. Since N≤100N \le 100N≤100, the total number of queries is at most 100010001000.

ppp