HDU 4027 can you answer these queries?

Source: Internet
Author: User
Can you answer these queries?

Time Limit: 4000/2000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 8501 accepted submission (s): 1942

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, PRI Nt 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 input101 2 3 4 6 7 8 9 1050 1 101 1 101 1 50 5 81 4 8 sample outputcase #1: 1976 sourcethe 36th ACM/ICPC Asia Regional Shanghai site -- online contest ------------ line segment tree... During the competition yesterday afternoon, I used a tree array. Examples and many examples have passed, but I don't know why Wa is always a day because I learned tree arrays? Debugging again in the morning for a long time, and Wa again many times .... brother dengyaolong AC the question within 30 s after the competition .... A pity .... = We are speechless. I don't know the line segment tree, but he doesn't know the tree array .... but it was solved later... After the competition, I re-typed the line segment tree code... 1y ~ It is not difficult to understand the meaning of this question. Enter n numbers, and then input M group operations. If it is 0, the number in the range is changed to its open side, but the integer is required. 1 indicates the sum of values in the view range. The following is the line segment Tree Code. The Code implemented by the tree array is unknown so far. >_<
#include<iostream>#include<cmath>#include<cstdio>#include<memory.h>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 100000+10#define ll long longll sum[maxn<<2];ll cnt[maxn<<2];void pushUp(int rt){    sum[rt] = sum[rt<<1] + sum[rt<<1|1];    cnt[rt] = cnt[rt<<1] && cnt[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 rt){    if(l == r)    {        sum[rt] = sqrt(sum[rt]+0.0);        if(sum[rt] <= 1)            cnt[rt] = 1;        return ;    }    int m = (l + r)>>1;    if(L <= m && !cnt[rt<<1]) update(L,R,lson);    if(R > m && !cnt[rt<<1|1]) update(L,R,rson);    pushUp(rt);}ll query(int L,int R,int l,int r,int rt){    if(L <= l && r <= R)    {        return sum[rt];    }    ll ret = 0;    int m = (l + r)>>1;    if(L <= m) ret += query(L,R,lson);    if(R > m) ret += query(L,R,rson);    return ret;}int main(){    #ifndef ONLINE_JUDGE    freopen("input.txt","r",stdin);    #endif    int n,m,l,r;    int step = 1,flag;    while(~scanf("%d",&n))    {        memset(sum,0,sizeof(sum));        memset(cnt,0,sizeof(cnt));        build(1,n,1);        printf("Case #%d:\n",step++);        scanf("%d",&m);        while(m--)        {            scanf("%d%d%d",&flag,&l,&r);            if(l > r)                swap(l,r);            if(flag == 0)                update(l,r,1,n,1);            else                printf("%I64d\n",query(l,r,1,n,1));        }        printf("\n");    }    return 0;}

Dengyaolong does not need to pass on new redirection skills, macro ~ \ (Too many rows )/~ I want to work hard and be happy ~~~~

HDU 4027 can you answer these queries?

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.