有一列数,(都是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. codevs1044四子连棋(Dfs)

    /* 数据范围太小 暴力暴力 Dfs直接 终止条件嘛 就是4中目标棋局 挨着枚举一遍就好了 搜索的起点一定是空格 当然 空格周围有黑有白 黑先走或者白先走答案可能不一样 所以 维护一个b 表示这一步走 ...

  2. 判断在Android手机内, 页面重新刷新一次

    <script type="text/javascript"> var UA = navigator.userAgent.toLowerCase(); //androi ...

  3. 13个简单有用的android开发代码

    1:查看是否有存储卡插入 String status=Environment.getExternalStorageState(); if(status.equals(Enviroment.MEDIA_ ...

  4. 读写Excel

    有读Excel,也有生成相同格式的Excel.需要引用Microsoft.Office.Interop.Excel.dll public string ShiPin() { //获取项目下的目录 st ...

  5. Delphi 动态改变Rzsplitter的Orientation(方向)属性

    效果图: 原先不知道,弄了半天都改不了RzSplitter.Orientation = orHorizontal / orVertical 然后去查该组件的源代码,原来Orientation不是在Rz ...

  6. 新手对css的浅识

    对于css的一个初步理解与认识 在最近的学习中接触到了之前自己从来都不曾想过的语言,C语言,html超文本标记语言等等,还有今天在这里我要进行分析的css,之前浏览过很多的网页,也曾想过这里面的秘密, ...

  7. [转]Traits 编程技法+模板偏特化+template参数推导+内嵌型别编程技巧

    STL中,traits编程技法得到了很大的应用,了解这个,才能一窥STL奥妙所在. 先将自己所理解的记录如下: Traits技术可以用来获得一个 类型 的相关信息的. 首先假如有以下一个泛型的迭代器类 ...

  8. Android之声音管理器《AudioManager》的使用以及音量控制

    以下为网上下载然后拼接-- Android声音管理AudioManager使用 手机都有声音模式,声音.静音还有震动,甚至震动加声音兼备,这些都是手机的基本功能.在Android手机中,我们同样可以通 ...

  9. PHP迭代器

    在所有语言中,所有迭代器都必须具有如下4想功能: 1.回滚迭代器到第一个元素 2.潜行到下一个元素 3.获取当前元素 4.验证是否到最后一个元素了 在PHP中我我们可以通过实现iterator来实现迭 ...

  10. 中文版kendoUI API — Grid(一)

    1.altRowTemplate 类型:Function | String 说明:提供表格行的交替模板,默认grid表格为每一个数据元素提供一个tr 注意:模板中最外层的html元素必须是<tr ...