http://acm.hdu.edu.cn/showproblem.php?pid=4027
Can you answer these queries?Time
limit:2000MS
Memory Limit:65768KB
64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 4027
Description
A lot of battleships of evil is arranged in a line before the battle. Our commander decides-to-use we secret weapon to eliminate the battleships. Each of the battleships can is marked a value of endurance. For every attack of We secret weapon, it could 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 is asked to answer the queries, the sum of the endurance of a consecutive part of the battleship line.
Notice that square root operation should is rounded down to integer.
Input
The input contains several test cases, terminated by EOF.
For each test case, the first line contains a single integer n, denoting there is n battleships of evil in a line. (1 <= N <= 100000)
The second line contains N integers Ei, indicating the endurance value of all battleship from the beginning of the line T o the end. You can assume this sum of all endurance value are less than 2 63.
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 would decrease the endurance value of the battleships between the X -th and y-th battleship, inclusive. The t=1 denoting the commander which ask for the sum of the endurance value of the battleship between a D y-th, inclusive.
Output
For each test case, print the case number at the first line. Then print one to 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 The main idea: N number of M operations, each operation has t,a,b, t = 0 o'clock the number of a to the number of B has become its own square root [sqrt (Al[i])] (rounding), t = 1 o'clock to find the number of A to B and "you can assume th At the sum of all endurance value are less than 2 63 "note with a long long
#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>#defineN 100010#defineLson root<<1, L, Tree[root]. Mid ()#defineRson root<<1|1, Tree[root]. Mid () + 1, Rusing namespacestd;structtree{intL, R; Long Longsum; intMid () {return(L + R)/2; } intLen () {return(R-l +1); }} tree[n*4];Long LongAl[n];voidBuild (intRootintLintR) {Tree[root]. L= L, Tree[root]. R =R; if(L = =R) {tree[root].sum=Al[l]; return ; } Build (Lson); Build (Rson); Tree[root].sum= tree[root<<1].sum + tree[root<<1|1].sum;}voidUpdate (intRootintLintR) { if(Tree[root]. Len () = =tree[root].sum)return;//Note that if we save the place, Tle will. if(Tree[root]. L = =Tree[root]. R) {tree[root].sum= (Long Long) sqrt (tree[root].sum); return ; } if(R <=Tree[root]. Mid ()) Update (Root<<1, L, R); Else if(L >Tree[root]. Mid ()) Update (Root<<1|1, L, R); Else{Update (Lson); Update (Rson); } tree[root].sum= tree[root<<1].sum + tree[root<<1|1].sum;}Long LongQuery (intRootintLintR) { if(Tree[root]. L = = L && tree[root]. R = =R)returntree[root].sum; if(R <=Tree[root]. Mid ())returnQuery (root<<1, L, R); Else if(L >Tree[root]. Mid ())returnQuery (root<<1|1, L, R); Else returnQuery (Lson) +Query (Rson);}intMain () {intN, M, I, T, a, B, x =0; while(~SCANF ("%d", &N)) {x++; for(i =1; I <= N; i++) scanf ("%i64d", &Al[i]); Build (1,1, N); scanf ("%d", &m); printf ("Case #%d:\n", x); while(m--) {scanf ("%d%d%d", &t, &a, &b); if(A >b) Swap (A, b);//Note that if the given a is larger than B, the two need to be swapped for position if(T = =0) Update (1, A, b); Elseprintf ("%i64d\n", Query (1, A, b)); } printf ("\ n"); } return 0;}
Hdu 4027 Can You answer these queries?