hdu 4027 Can you answer these queries?区間のN回根と線分樹を求めます.

3978 ワード

Problem Description
A lot of battleships of evil arranged in a line before the battle.Our command decides to use our secret weaton to eliminate the battleships.Each of the battleships can be market a value of endurance.Fotteweryit could decrease the endurance of a consecutive parts of battleships by make their endurance to the square root of it original value of endurance.During the series of aut secret weappon,the command want the the the the evarever the
You are asked to answer the queries that the sum of the endurance of a consecutive parts of the battleship line.
Notice that the square root operation shound 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 re re N battleships of evil 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 the the end.You can asom that the sum of all endurance valuse less less than 2
63.
  The next line contains an integer M,denoting the number of actions and queries.(1<=M<=100000)
  For the follwing M lines,each line contains three integers T,X and Y.The T=0 denoting the action of the secret weaton,which will decrease the endurance value of the battles between the-th Yotinclusive.The T=1 denoting the query of the command 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.The n print one line for each query.And remember follow a blank line after each test case.
 
 
Sample Input
10 1 2 3 4 5 5 6 7 7 9 10 0 1 10 1 1 10 1 1 1 5 0 5 8 1 8 8 8
 
 
Sample Output
Case菗1:19 7
 
 //
萼include荫荫include菷菵include菵菵菵include using namespace std;define bignum long const int maxn=110000;struct Trie{    int left、right    bignum sum    int pw;Trie tree[maxn*4]bignum a[maxn]void buildtree(int id,int l,int r){    tree[id].left=l,tree[id].right=r;    tree[id].pw=1;    if(l!=r)    {        int mid=(l+r)>>1        buildtree(id<<1,l,mid);        buildtree((id<<1)|1,mid+1,r)        tree[id].sum=tree[id<<1].sum+tree[(id<<1)|1].sum;    }     else    {        tree[id].sum=a[l]    } } void udate(int id,int l,int r)/[l,r]pw*2,sum reet{    if(tree[id].pw>64)return;/impotant    if(tree[id].left==tree[id].right)    {        tree[id].sum=sqrt(tree[id].sum+0.0)        tree[id].pw*=2;        return;    }     int mid=(tree[id].left+tree[id].right]>1    if(r<=mid)udate(id<<1,l,r);    else if(l)=mid+1)udate((id<<1)|1,l,r)    else    {        udate(id<<1,l,mid);        uudate((id<<1)|1,mid+1,r)    }     if(tree[id]<<1].pw==tree[(id<<1].pw)tree[id].pw=tree[id].pw]    else tree[id].pw=-1;    tree[id].sum=tree[id<<1].sum+tree[(id<<1].sum;]bignum query(int id,int l,int r){    if(tree[id].left==l&tree[id].right==r)    {        return tree[id].sum    }     int mid=(tree[id].left+tree[id].right]>1    if(r==mid)return query(id<<1,l,r);    else if(l)=mid+1)return query(id<<1)|1,l,r)    else    {        return query(id<<1,l,mid)+query((id<<1)|1,mid+1,r)    } } int main(){    int n,pl=1    while(scanf("%d"、&n)==1)    {        for(int i=1;i<=n;i+)scanf(“%I 64 d”、&a[i]);        buildtree(1,1,n)        int q;scanf("%d"、&q);        printf("Case菗% d:",pl+);        while(q--)        {            int d,l,r;scanf('%d%d%"、&d,&d,&l,&r);            if(l>r)swap(l,r)            if(d==0)            {                udate(1、l、r)            }             else            {                bignum cnt=query(1,l,r)                printf(「%I 64 d」、cnt)            }         }         printf(");    }     return 0;