DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
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 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
Editorial

Cutting Bamboo

Back to problem

Editorial

The interior of a segment meets y=0y=0y=0 exactly when its endpoint Y-coordinates have opposite signs. With the same sign the entire segment stays on one side; with one zero the intersection is only an endpoint. Both cannot be zero by the constraints. Count precisely the opposite-sign pairs. This takes O(∑N)O(\sum N)O(∑N) time and O(1)O(1)O(1) auxiliary space. The naive product test Y1,iY2,i<0Y_{1,i}Y_{2,i}<0Y1,i​Y2,i​<0 also works. Its product has magnitude at most 101210^{12}1012, so use 64-bit integers.

Solution written by GPT6.1