How to solve this (Codeforces EDU two pointers)

Problem link
How to solve this problem? I am stuck on the part that how to calculate gcd of changing segments in the given time limit.

You can use a sparse table or a segment tree. Just google these data structures.

2 Likes