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
fardin_abir: 2020-01-25 17:15:18

a good problem for propagation...

its_himanshu: 2020-01-16 06:08:48

Really annoying time constraint...

hduoc2003: 2019-09-22 08:42:32

damn it -_-. many times get wa because of using cerr :D

debarun: 2019-08-23 20:20:49

This is my first problem where using cin/cout with fast i/o didn't work. Whereas, scanf-printf got my job done!

iviosab: 2019-03-17 19:10:43

Note that Ai may hold a negative number, this was not mentioned in the statement

megatron10599: 2019-02-14 16:14:40

Purely for optimization, sacrificed code quality for AC

raghavgarg098: 2019-01-01 09:06:14

Last edit: 2019-01-01 09:17:39
phoemur: 2018-10-21 01:35:17

Don't forget edge cases, when a query(l, r) has l > r;
Costed me 4 WA

tanardi gunawan: 2018-10-04 10:26:01

just pruning got ac

shizukaa: 2018-07-29 12:40:53

Key points:
1) Make your array long long instead of int. Type checking taking longer time I guess.
2) Use scanf and printf instead of cin and cout.

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