Hdu4027 can you answer these queries? (Decrease of the square of a line segment tree and sum of intervals)

Source: Internet
Author: User

Reprinted please indicate the source: http://blog.csdn.net/u012860063

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4027

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


The Code is as follows:

# Include <cstdio> # include <cmath> # include <cstring> # include <string> # include <cstdlib> # include <climits> # include <ctype. h> # include <queue> # include <stack> # include <vector> # include <deque> # include <set> # include <map> # include <iostream> # include <algorithm> using namespace STD; # define PI ACOs (-1.0) # define INF 0x3fffffffusing namespace STD; # define lson L, M, RT <1 # define rson m + 1, R, RT <1 | 1 // Lson and rson indicate the left son and right son of the node. // RT indicates the root of the current subtree ), that is, the current node const _ int64 maxn = 111111; // maxn is the maximum range given by the question, and the number of nodes must be four times larger, specifically, the number of nodes must be twice the minimum 2x greater than maxn _ int64 sum [maxn <2]; void pushup (int rt) // update the information of the current node to the parent node {sum [RT] = sum [RT <1] + sum [RT <1 | 1];} void build (int l, int R, int RT) {If (L = r) {scanf ("% i64d", & sum [RT]); return ;} int M = (L + r)> 1; build (lson); Build (rson); pushup (RT);} void Update (int l, int R, int l, int R, int R T) {If (L = r) {sum [RT] = SQRT (sum [RT]); return;} int M = (L + r)> 1; if (L <= m) Update (L, R, lson); If (M <r) Update (L, R, rson); pushup (RT );} __int64 query (int l, int R, int L, int R, int RT) {If (L <= L & R <= r) {return sum [RT];} int M = (L + r)> 1 ;__ int64 ret = 0; If (L <= m) RET + = query (L, r, lson); If (M <r) RET + = query (L, R, rson); return ret;} int main () {int N, Q, T, k = 0; int A, B, C; whi Le (~ Scanf ("% d", & N) {build (1, n, 1); // build printf ("case # % d: \ n ", + + k); scanf ("% d", & Q); While (Q --) // Q indicates the number of inquiries {// char op [2]; int op; int A, B, C; scanf ("% d", & OP, & A, & B); If (A> B) {int T; T = A, A = B, B = T;} If (OP = 1) {printf ("% i64d \ n", query (A, B, 1, n, 1);} else {If (query (A, B, 1, n, 1 )! = B-A + 1) Update (A, B, 1, n, 1) ;}} printf ("\ n");} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.