zoukankan      html  css  js  c++  java
  • Can you answer these queries? HDU

    Can you answer these queries? HDU - 4027 

    A lot of battleships of evil 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 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 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 should 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 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 line to the end. You can assume that the sum of all endurance value is 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 will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. 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

    10
    1 2 3 4 5 6 7 8 9 10
    5
    0 1 10
    1 1 10
    1 1 5
    0 5 8
    1 4 8

    Sample Output

    Case #1:
    19
    7
    6

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <map>
    #include <set>
    #include <list>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <iomanip>
    #define ull unsigned long long
    #define ll long long
    #define pb push_back
    #define mem(sum,x) memset(sum,x,sizeof(sum))
    #define rep(i,start,end) for(int i=start;i<=end;i++)
    #define per(i,end,start) for(int i=end;i>=start;i--)
    #define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    using namespace std;
    const int mod = 998244353;
    const int mxn = 1e5 +7;
    int _,n,m,t,u,v,ans,cnt,ok,lim;
    ll w[mxn] , cost[mxn] ,  far[mxn] , siz[mxn];
    double num[mxn];
    #define lc now<<1
    #define rc now<<1|1
    string str ;
    struct node {ll l,r,val,lazy,mx,mn;}p[mxn<<4];
    void pushup(int now){
        p[now].val = p[lc].val+p[rc].val;
        /// p[now].mx = max(p[lc].mx , p[rc].mx);
        /// p[now].mn = min(p[lc].mn , p[rc].mn);
    }
    void pushdown(int now)
    {
        if(p[now].lazy)
        {
            p[lc].lazy = p[rc].lazy = p[now].lazy;
            p[lc].val = p[now].lazy*(p[lc].r-p[lc].l+1);
            p[rc].val = p[now].lazy*(p[rc].r-p[rc].l+1);
            p[now].lazy = 0 ;
        }
    }
    void build(int l,int r,int now)
    {
        p[now].l = l,p[now].r = r ;///, p[now].lazy = 0 ;
        if(l==r){
            /// cin>>p[now].val;
            scanf("%lld",&p[now].val);
            return ;
        }
        int mid = (l+r)>>1;
        build(l,mid,lc);build(mid+1,r,rc);pushup(now);
    }
    void add(int l,int r,int now)
    {
        if(p[now].r-p[now].l+1 == p[now].val) return ;
        if(p[now].l==p[now].r)
        {
            p[now].val = sqrt(p[now].val);
            return ;
        }
        ///pushdown(now);
        int mid = (p[now].l+p[now].r)>>1;
        if(l<=mid) add(l,r,lc);
        if(r>mid) add(l,r,rc);
        pushup(now);
    }
    ll ask(int l,int r,int now)
    {
        if(p[now].l>=l && p[now].r<=r)
        {
            return p[now].val;
        }
        int mid = (p[now].l+p[now].r)>>1;
        ll ans = 0 ;
        if(l<=mid) ans+=ask(l,r,lc);
        if(r>mid) ans+=ask(l,r,rc);
        return ans;
    }
    int main()
    {
        tle;int Case = 1 ;
        while(~scanf("%d",&n))
        {
            printf("Case #%d:
    ",Case++);
            build(1,n,1);
            scanf("%d",&m);
            int k,l,r;
            while(m--)
            {
                cin>>k>>l>>r;
                if(l>r) swap(l,r);
                if(k) printf("%lld
    ",ask(l,r,1));
                else add(l,r,1);
            }
            printf("
    ");
        }
    }
    所遇皆星河
  • 相关阅读:
    angular 路由动态加载JS文件
    使用AngularJS处理单选框和复选框的简单方法
    angularjs 请求后端接口请求了两次
    angular ui.router 路由传参数
    linux 安装svn服务器
    gulp css 压缩 合并
    ajax 实现跨域
    [codeforces 1366D] Two Divisors
    Namomo Test Round 1 题解
    Race(淀粉质)
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/12828882.html
Copyright © 2011-2022 走看看