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
/* Segment tree segments updated open square root Remember if ans==r-l+1, you do not have to update, otherwise tle*/#include <bits/stdc++.h>using namespace std;const int MAX = 1e6 + 10; Long Long Sum[max << 2];long long a[max];int n;void build (long long RT, Long long L, long long R) {Sum[rt] = 0; if (L = = r) {Sum[rt] = a[l]; Return } Long Long mid = L + R >> 1; Build (Rt*2, L, mid); Build (Rt*2+1, mid + 1, R); SUM[RT] = sum[rt*2] + sum[rt*2+1];} void update (Long long RT, Long long L, long long R, Long long L, long long R) {if (L = = r) {Sum[rt] = sqrt (sum[rt ]); Return } Long Long mid = L + R >> 1; if (l <= mid) Update (RT*2, L, Mid, L, R); if (R > Mid) Update (rt*2+1, mid + 1, R, L, R); SUM[RT] = sum[rt*2] + sum[rt*2+1];} Long long RT, Long long L, long long R, Long long R, long long L, {if (L <= l && R >= R) return SUM[RT]; Long long mid = L + R >> 1; Long long ret = 0; if (L <= mid) ret + = query (Rt*2, L, Mid, L, R); If(R > Mid) ret + = query (rt*2+1, mid+1, R, L, R); return ret;} int main () {int cas = 1; while (~SCANF ("%d", &n)) {printf ("Case #%d:\n", cas++); for (int i = 1; I <= n; i++) scanf ("%i64d", &a[i]); Build (1, 1, N); int m; scanf ("%d", &m); int flag; Long long L, R; while (m--) {scanf ("%d%i64d%i64d", &flag, &l, &r); if (l >= r) swap (L, R); if (flag) {long long ans = query (1, 1, N, L, R); printf ("%i64d\n", ans); } else {long long ans = query (1, 1, N, L, R); if (ans! = r-l + 1) Update (1, 1, N, L, R); }} puts (""); } return 0;}
hdu4027--segment tree into segments update--can You answer these queries?