Contest.uni-smr.ac.ru :: соревнования по программированию
Русская версия || English version
Login:
Password:
Забыли пароль?
 пример поиска: Вася Пупкин
 






Задача C для тренировки в сентябре

Первоисточник: ACM ICPC 2009 -2010, NEERC, Northern Subregional Contest St Petersburg, October 17, 2009

Задачу добавил: elena

Успешно сдано решений: 2

Problem E.  Enigmatic Device

Time limit: 3 seconds
Memory limit: 256 megabytes

Yes, it happened! The first contact! Aliens will visit the Earth in2010! And they promised to bring an enigmatic device which cannot be constructed using existing Earth technologies. Most of the scientists of the world think so! All newspapers already published their leading articles about it. This device will accept an integer sequence {ai} as its initial input. After that, it can perform the following two operations:

1. Take an interval [l; r] and perform ai <-  ai^2 mod 2010 for all ai such that l <= i <= r.
2. Take an interval [l; r] and output the sum of all ai such that l <= i <= r. Note that the sum is not taken modulo 2010.

The amazing thing about this device is that it is able to perform 50 000 operations of this kind with a sequence of 50 000 numbers within 3 seconds. Nobody could do it before!
But Roman does not believe in aliens and thinks that it is only a great hoax made by somebody just to
win another million bucks on the stock exchange. His goal is to prove this. So he hired you to write a
program to simulate this device.
Given an integer sequence ai and a sequence of operations, write a program which simulates the behaviour of the strange alien device.

Input
The first line of the input contains the length of the sequence n (1 <= n <= 50 000). The second line contains n numbers ai forming the initial sequence (0 <= ai <= 2009). The third line contains the number of operations m (1 <= m <= 50 000). The rest of file contains m lines, each describing one operation. The j-th operation is described by its kind kj ('1' for squaring, '2' for calculating the sum), followed by two integers lj and rj (1 <= lj <= rj <= n).

Output
For each operation of the second kind, write their output on the separate line, in order they appear in the input.

Example

input.txt
3
17 239 999
4
2 1 3
1 2 3
2 2 3
2 1 2

output.txt
1255
1882
858

Сдать задачу

Задать вопрос жюри по этой задаче