DOJ logoDOJ
LoginRegister
DOJ logoDOJ
Call for Tasks
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

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
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Editorial

Sequence Operations

Back to problem

Editorial

Transform a sequence using Xi=2∑k<iAk+AiX_i=2\sum_{k<i}A_k+A_iXi​=2∑k<i​Ak​+Ai​. After removing position iii, consider a later position jjj. If j−ij-ij−i is odd, the preceding sum decreases by AiA_iAi​ and that element increases by 2Ai2A_i2Ai​. If it is even, the preceding sum increases by AiA_iAi​ and the element decreases by 2Ai2A_i2Ai​. Thus its transformed value is unchanged. The operation simply deletes one transformed value. The transformation is invertible: given the preceding sum PPP, recover the next element as Xi−2PX_i-2PXi​−2P. Therefore equal resulting sequences correspond exactly to common subsequences of the transformed sequences. If their LCS has length LLL, the answer is N+M−2LN+M-2LN+M−2L. For subtask 1, enumerate actual deletion states and compare common states. There are at most 2N2^N2N states; an ordered-set implementation has the conservative bound O((2N+2M)(N+M)3)O((2^N+2^M)(N+M)^3)O((2N+2M)(N+M)3). The full solution uses LCS DP in O(NM)O(NM)O(NM) time and O(M)O(M)O(M) memory. Initially ∣Xi∣≤49 995 000|X_i|\le49\,995\,000∣Xi​∣≤49995000. Every later transformed sequence is a subsequence, so every reconstructed element has magnitude at most (2⋅5000−1)49 995 000<5⋅1011(2\cdot5000-1)49\,995\,000<5\cdot10^{11}(2⋅5000−1)49995000<5⋅1011. Signed 64-bit integers suffice. Solution written by GPT6.1