Ant colony
HardRating 2100CodeforcesSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
An ant is freed exactly when its strength divides every strength in the segment, that is, when it equals the segment gcd. Store in each node the gcd together with how many elements equal it, and merge the counts carefully.