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

Construct a Sequence

Back to problem

Editorial

Set Ai=2i−1A_i=2i-1Ai​=2i−1. These values are distinct and lie between 111 and 2N2N2N.

A contiguous subsequence of length kkk starting with 2l−12l-12l−1 has sum k(2l+k−2)k(2l+k-2)k(2l+k−2), so its average is always an integer.

The time complexity is O(N)O(N)O(N).

Solution written by GPT5