有一列数,(都是2^63范围内的并且都大于0的整数),现在呢有一些操作, 操作 0 可以把区间LR内的所有数都变成它的平方根数(是取整后的),操作 1 可以就是求区间LR内的和了。
分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底。、
注意:给的X Y大小未知,会出现X > Y的情况
*************************************************************************
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std; #define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R const int maxn = ; struct Tree
{
    int L, R;
    long long sum;
    int Mid(){return (L+R)/;}
    int Len(){return (R-L+);}
}tree[maxn*];
long long val[maxn]; void Build(int root, int L, int R)
{
    tree[root].L = L, tree[root].R = R;     if(L == R)
    {
        tree[root].sum = val[L];
        return ;
    }     Build(Lson);
    Build(Rson);     tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
}
void Insert(int root, int L, int R)
{
    if(tree[root].Len() == tree[root].sum)
        return ;
    if(tree[root].L == tree[root].R)
    {
        tree[root].sum = (long long)sqrt(tree[root].sum*1.0);
        return ;
    }     if(R <= tree[root].Mid())
        Insert(root<<, L, R);
    else if(L > tree[root].Mid())
        Insert(root<<|, L, R);
    else
    {
        Insert(Lson);
        Insert(Rson);
    }     tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
}
long long Query(int root, int L, int R)
{
    if(tree[root].L == L && tree[root].R == R)
        return tree[root].sum;     if(R <= tree[root].Mid())
        return Query(root<<, L, R);
    else if(L > tree[root].Mid())
        return Query(root<<|, L, R);
    else
        return Query(Lson)+Query(Rson);
} int main()
{
    int i, N, M, t=;     while(scanf("%d", &N) != EOF)
    {
        for(i=; i<=N; i++)
            scanf("%lld", &val[i]);
        Build(, , N);         scanf("%d", &M);         int c, a, b;
        long long ans;         printf("Case #%d:\n", t++);
        while(M--)
        {
            scanf("%d%d%d", &c, &a, &b);
            if(a > b)swap(a, b);
            if(c == )
                Insert(, a, b);
            else
            {
                ans = Query(, a, b);
                printf("%lld\n", ans);
            }
        }
        printf("\n");
    }     return ; } 

H - Can you answer these queries? - (区间查询更新)的更多相关文章

  1. H - Can you answer these queries? ( POJ - 3264 )

    H - Can you answer these queries? HDU - 4027   思路: 一眼思路:线段树区间修改,区间查询. 发现bug:区间的sqrt无法实现,所以还是相当于对区间的每 ...

  2. SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)

    GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...

  3. HDU 4027 Can you answer these queries? (线段树区间修改查询)

    描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to u ...

  4. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

  5. Can you answer these queries?

    Can you answer these queries? Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & ...

  6. hdu4027Can you answer these queries?【线段树】

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  7. HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】

    Can you answer these queries? Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & ...

  8. kuangbin专题七 HDU4027 Can you answer these queries? (线段树)

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  9. HDU 4027 Can you answer these queries?(线段树区间开方)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

随机推荐

  1. 怎么在后台修改前台html页面的key、title、description

    public void UpdateMeta(string title, string keyword, string desc) { ; i >= ; i--) { if (this.Head ...

  2. 转载:C#中事件和委托的编译代码

    接上文转载:C#中事件的由来,这时候,我们注释掉编译错误的行,然后重新进行编译,再借助Reflactor来对 event的声明语句做一探究,看看为什么会发生这样的错误: public event Gr ...

  3. python面对对象编程---------6:抽象基类

    抽象基本类的几大特点: 1:要定义但是并不完整的实现所有方法 2:基本的意思是作为父类 3:父类需要明确表示出那些方法的特征,这样在写子类时更加简单明白 用抽象基本类的地方: 1:用作父类 2:用作检 ...

  4. jq之简单表单验证

    <body> <form method="post" action=""> <div class="int"& ...

  5. 获取html页面所有的img标签

    #region 获取html中所有Img Regex r = new Regex(@"<img[\s\S]*?>", RegexOptions.IgnoreCase); ...

  6. js星级评分点击星级评论打分效果--收藏--转载

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. node.js动态调试

    supervisor node ./bin/www npm start 不会动态运行和调试程序,相当于动态部署

  8. (转)Android Touch事件传递机制

    -----来源:http://www.trinea.cn/android/touch-event-delivery-mechanism/ 介绍Android Touch事件的传递机制. 不少朋友私信问 ...

  9. Css四种样式

    1. 2 3 4 5 6.

  10. VS2012 ActiveX控件_D接口添加方法事项

    自己写的是Clock控件,所以控件的接口是_DClock 使用向导添加方法后,会在紫色区域自动生成红色代码:(添加Hello方法) dispinterface _DClock { properties ...