Can you answer these queries? Time Limit: 4000/2000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 8330 accepted submission (s): 1904
Problem descriptiona lot of battleships of edevil are arranged in a line before the battle. our commander decides to use our secret weapon to eliminate the battleships. each of the battleships can be marked a value of endurance. for every attack of our secret weapon, it cocould decrease the endurance of a consecutive part of battleships by make their endurance to the square root of it original value of endurance. during the series of attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you for help.
You are asked to answer the queries that the sum of the endurance of a consecutive part of the battleship line.
Notice that the square root operation shocould be rounded down to integer.
Inputthe input contains several test cases, terminated by EOF.
For each test case, the first line contains a single integer N, denoting there are n battleships of edevil in a line. (1 <= n <= 100000)
The second line contains N integers EI, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 263.
The next line contains an integer m, denoting the number of actions and queries. (1 <= m <= 100000)
For the following M lines, each line contains three integers t, X and Y. the T = 0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, Volume Sive. the T = 1 denoting the query of the Commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.
Outputfor each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.
Sample Input
101 2 3 4 5 6 7 8 9 1050 1 101 1 101 1 50 5 81 4 8
Sample output
Case #1:1976
For example, if the number is 100000, 0 I j indicates that all numbers in the I j segment are taken as the root number (rounded down ), 1 I j indicates the sum of all values between I j... (No more than 64 bits)... all are pitfalls !!!
# Include <cstdio> # include <math. h ># include <iostream> using namespace STD; int n, m ;__ int64 A [100010]; struct node {int left, right; bool flag; // indicates whether the value is '1', _ int64 power;} p [400040]; void build (int I, int L, int R) {P [I]. left = L; P [I]. right = r; P [I]. flag = 1; if (L = r) {P [I]. power = A [l]; if (a [l] <= 1) P [I]. flag = 0; return;} int M = (L + r)/2; build (I * 2, l, m); Build (I * 2 + 1, m + 1, R); P [I]. power = P [I * 2]. power + P [I * 2 + 1]. power; P [I]. flag = P [I * 2]. flag | P [I * 2 + 1]. flag;} void Update (int I, int L, int R) {If (P [I]. flag = 0) return; If (P [I]. left = P [I]. right & P [I]. left = L & P [I]. right = r) {P [I]. power = (_ int64) SQRT (1.0 * P [I]. power); If (P [I]. power <= 1) P [I]. flag = 0; return;} int M = (P [I]. left + P [I]. right)/2; If (r <= m) Update (I * 2, L, R); else if (L> m) Update (I * 2 + 1, l, r); else {Update (I * 2, l, m); Update (I * 2 + 1, m + 1, R);} p [I]. power = P [I * 2]. power + P [I * 2 + 1 ]. Power; P [I]. flag = P [I * 2]. flag | P [I * 2 + 1]. flag ;}__ int64 query (int I, int L, int R) {If (P [I]. left = L & P [I]. right = r) return P [I]. power; _ int64 ans = 0; int M = (P [I]. left + P [I]. right)/2; If (r <= m) ans + = query (I * 2, L, R); else if (L> m) ans + = query (I * 2 + 1, L, R); else ans + = (query (I * 2, l, m) + query (I * 2 + 1, m + 1, R); Return ans;} int main () {int K = 1, I, X, Y, Z, mm, B; while (scanf ("% d", & N )! = EOF) {for (I = 1; I <= N; I ++) scanf ("% i64d", & A [I]); Build (1, 1, n ); printf ("case # % d: \ n", K ++); scanf ("% d", & M); While (M --) {scanf ("% d", & X, & mm, & B); Z = mm> B? MM: B; y = mm> B? B: mm; If (x = 0) Update (1, y, z); If (x = 1) printf ("% i64d \ n", query (1, y, z);} printf ("\ n"); // tianyao, It is not seen ,....} Return 0 ;}