GSS4 - Can you answer these queries IV

You are given a sequence A of N(N <= 100,000) positive integers. There sum will be less than 1018. On this sequence you have to apply M (M <= 100,000) operations:

(A) For given x,y, for each elements between the x-th and the y-th ones (inclusively, counting from 1), modify it to its positive square root (rounded down to the nearest integer).

(B) For given x,y, query the sum of all the elements between the x-th and the y-th ones (inclusively, counting from 1) in the sequence.


Multiple test cases, please proceed them one by one. Input terminates by EOF.

For each test case:

The first line contains an integer N. The following line contains N integers, representing the sequence A1..AN.
The third line contains an integer M. The next M lines contain the operations in the form "i x y".i=0 denotes the modify operation, i=1 denotes the query operation.


For each test case:

Output the case number (counting from 1) in the first line of output. Then for each query, print an integer as the problem required.

Print an blank line after each test case.

See the sample output for more details.


1 2 3 4 5
1 2 4
0 2 4
1 2 4
0 4 5
1 1 5
10 10 10 10
1 1 4
0 2 3
1 1 4

Case #1:

Case #2:

hide comments
siddharth_0196: 2016-12-26 15:30:26

Inclusion of 1 statement can change TLE to AC! :D

Rohit Sharma: 2016-10-31 08:13:46

beware x>y in this problem

segorov: 2016-10-06 16:41:50

if (l > r) swap(l, r);
It helped me to solve this task. Too weird...

blinkingstar: 2016-09-26 16:21:06

@munjal Like if (x > y) while(1) {} ?

munjal: 2016-09-07 19:12:01

@Ryuzaki How did you know the test cases.

karan_batra: 2016-09-05 21:59:51

Declaring array to be int gives TLE, when declared long long gives AC(Guess type checking takes too much time). Too strict time constraint -_-.

liuxueyang: 2016-07-24 14:48:06

cin and cout will TLE in c++, use scanf and printf.
Besides, in the problem, it doesn't assume x and y who is bigger... ;-)

Pulkit Singhal: 2015-09-03 09:17:44

UFDS + BIT, Nice problem
But x > y in many cases

sebinechita: 2015-07-13 16:20:54

in the case where x > y you should swap x and y and than do the algorithm

Ryuzaki: 2014-01-27 04:31:14

Test cases are weird.
X > Y in many of them.

Added by:Fudan University Problem Setters
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO PERL6
Resource:Own problem, used in ACM/ICPC Regional Contest, Shanghai 2011 preliminary