HDU 4027 Can you answer these queries (segment tree update)

Source: Internet
Author: User

HDU 4027 Can you answer these queries (segment tree update)

 

Problem Description A 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.
Input The 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.

Output For 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

Question: give a new interval, but the difference is that the number of this interval is rooted,

 

 

Idea: because a root number after a certain number is 1, it will not change any more. There is no need to change the number of segments, so it can save time, this Code also times out with G ++ and has been handed over by c ++.

 

 

 

 

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8typedef _ int64 ll; # define fre (I, a, B) for (I = a; I
          
            = A; I --) # define mem (t, v) memset (t), v, sizeof (t) # define ssf (n) scanf ("% s ", n) # define sf (n) scanf ("% d", & n) # define sff (a, B) scanf ("% d", &, & B) # define sfff (a, B, c) scanf ("% d", & a, & B, & c) # define pf printf # define bug pf ("Hi \ n") using namespace std; # define INF 0x3f3f3f3f # define N 1000005 struct stud {int le, ri; ll len, sum;} f [N * 4]; ll a [N]; inline void pushup (int pos) {f [pos]. sum = f [L (pos)]. sum + f [R (pos)]. sum;} void build (int pos, int le, int ri) {f [pos]. le = le; f [pos]. ri = ri; f [pos]. len = ri-le + 1; if (le = ri) {f [pos]. sum = a [le]; return;} int mid = MID (le, ri); build (L (pos), le, mid); build (R (pos ), mid + 1, ri); pushup (pos);} void hello (int pos) // returns the root number of The number of this range {if (f [pos]. len = f [pos]. sum) return; if (f [pos]. le = f [pos]. ri) {f [pos]. sum = (ll) (sqrt (f [pos]. sum + 0.0); return;} hello (L (pos); hello (R (pos); pushup (pos);} void update (int pos, int le, int ri) {if (f [pos]. len = f [pos]. sum) return; if (f [pos]. le = le & f [pos]. ri = ri) {hello (pos); return;} int mid = MID (f [pos]. le, f [pos]. ri); if (mid> = ri) update (L (pos), le, ri); elseif (mid
           
             = Ri) return query (L (pos), le, ri); elseif (mid
            
              Ri) swap (le, ri); if (op) pf ("% I64d \ n", query (1, le, ri); else update (1, le, ri);} pf ("\ n");} return 0 ;}
            
           
          
        
       
      
     
    
   
  
 


 

Related Article

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.