Enigmatic Device
Time limit3sMemory limit256 MB
Given an array, support range squaring modulo 2010 and range sum queries, using the fact that values cycle quickly under repeated squaring.
- Level
Medium6 of 10
- Topics
- Segment tree, Math, Implementation
- Solved
- No attempts yet
Problem
A curious device stores an integer sequence and repeatedly transforms it. It supports two kinds of operations:
- Square — given an interval , replace for every index with .
- Sum — given an interval , output . This running sum is not reduced modulo 2010.
Simulate the device: apply each squaring operation and answer each sum query.
Input
The first line contains the sequence length ().
The second line contains integers , the initial sequence ().
The third line contains the number of operations ().
Each of the next lines describes one operation with three integers , , : squares the interval, queries its sum, and .
Output
For each operation of the second kind, print its result on its own line, in the order the queries appear in the input.