Enigmatic Device | 프로그래밍의 벗 PivotOJ
PivotOJ

Enigmatic Device

시간 제한: 3000ms메모리 제한: 256MB출처: NEERC Northern Subregional 2009BOJ 3554

문제

Yes, it happened! The first contact! Aliens will visit the Earth in 2010! 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}\{a_i\} as its initial input. After that, it can perform the following two operations:

  1. Take an interval [l;r][l; r] and perform aiai22010a_i \leftarrow a_i^2 \bmod 2010 for all aia_i such that lirl \le i \le r.
  2. Take an interval [l;r][l; r] and output the sum of all aia_i such that lirl\le i\le r. Note that the sum is not taken modulo 2010.

The amazing thing about this device is that it is able to perform 5000050\,000 operations of this kind with a sequence of 5000050\,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 aia_i and a sequence of operations, write a program which simulates the behaviour of the strange alien device.

입력

The first line of the input contains the length of the sequence nn (1n500001\le n\le 50\,000). The second line contains nn numbers aia_i forming the initial sequence (0ai20090\le a_i\le 2009). The third line contains the number of operations mm (1m500001\le m\le 50\,000). The rest of file contains mm lines, each describing one operation. The jj-th operation is described by its kind kjk_j (1 for squaring, 2 for calculating the sum), followed by two integers ljl_j and rjr_j (1ljrjn1\le l_j \le r_j\le n).

출력

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

예제

예제 1

입력
3
17 239 999
4
2 1 3
1 2 3
2 2 3
2 1 2
출력
1255
1882
858
코드를 제출하려면 로그인하세요.