#C5167. Dynamic Range GCD Queries
Dynamic Range GCD Queries
Dynamic Range GCD Queries
You are given a sequence of \( n \) integers and must perform \( m \) operations on this sequence. The operations are of two types:
- GCD Query: Given indices \( L \) and \( R \) (1-indexed), compute the greatest common divisor (GCD) of the subarray from \( L \) to \( R \).
- Update: Given an index \( i \) (1-indexed) and a value \( x \), update the \( i^{th} \) element of the sequence to \( x \).
Your task is to process these operations efficiently and output the result for each GCD query.
inputFormat
The first line contains two integers \( n \) and \( m \), where \( n \) is the number of elements in the sequence and \( m \) is the number of operations.
The second line contains \( n \) space-separated integers representing the initial sequence.
Each of the next \( m \) lines describes an operation in one of the following formats:
1 L R
: A GCD query for the subarray between indices \( L \) and \( R \) (inclusive).2 i x
: An update operation, setting the \( i^{th} \) element to \( x \).
outputFormat
For each GCD query, output the computed GCD on a new line.
## sample5 4
2 4 6 8 10
1 1 5
2 3 12
1 2 4
1 1 5
2
4
2
</p>