Algebra on Segment
Time limit10sMemory limit512 MB
Given an array modulo a prime p, support range multiplication and report the order of the subgroup generated by the elements of a segment.
- Level
Hard8 of 10
- Topics
- Segment tree, Number theory, Math
- Solved
- No attempts yet
Problem
Consider a prime number .
All operations below are performed in the multiplicative group modulo .
You are given an array of size . Process queries of two types:
- "1 ": multiply all elements of the segment by .
- "2 ": find the order of the subgroup generated by the elements of the segment .
See the notes below for the definitions.
Input
The first line contains three integers , , : the prime number, the size of the array, and the number of queries (, is prime, , ).
The second line contains the initial array of size ().
Each of the next lines is a query. A query of the first type has the form "1 " (, ) and multiplies all elements of by . A query of the second type has the form "2 " () and asks for the order of the subgroup generated by the elements of .
Output
For each query of the second type, print the answer on a separate line.
Notes
This section defines the group theory terms used in the statement. All definitions are standard, so readers who know the basics can skip it.
A group is a set with an associative binary operation. The group is closed under the operation, has an identity element (1 for multiplication), and every element has an inverse.
The multiplicative group modulo a prime has elements , and the operation is multiplication modulo . It is easy to check that this is a group.
A subgroup is a subset of a group that is itself a group under the operation of . In particular, it is closed under the operation.
The subgroup generated by a set is , the smallest subgroup of that contains . This subgroup is unique.
The order of a group is the number of elements in it.