有一列数,(都是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. codevs 2495 水叮当的舞步IDA*

    /* 比较简单的A* 估价函数很简单就是除了左上角的联通快之外的不同的个数 加上迭代 好像答案最多在16步之内出解 这样裸裸的交上去是50分 在考虑剪枝 每个选颜色的时候一定是选左上角联通快附近的颜色 ...

  2. C#中的IO流操作(FileStream)

    StreamReader和StreamWriter适用于对文本文件的操作,因为它是以字符为单位进行的操作 不用担心编码问题 using (Stream s = new FileStream(@&quo ...

  3. HTML (1)href与Action,get post

    1.   href与Action的区别 href只能get参数,action能get参数又能post参数 href一般用于单个连接,可以带参数(URL重写),是采用get方式请求的,在地址栏中可以看到 ...

  4. Android中px、dp、sp的区别

    px: 即像素,1px代表屏幕上一个物理的像素点: px单位不被建议使用,因为同样100px的图片,在不同手机上显示的实际大小可能不同,如下图所示(图片来自android developer guid ...

  5. asp.net中过滤器的两种写法

    1.写在一个单独的类库中在web.config中进行配置 <httpModules> <add name="" type="类的全名称,程序集的名称&q ...

  6. 关于异常的疑难解答:System.Runtime.InteropServices.COMException

    COMException exception is thrown when an unrecognized HRESULT is returned from a COM method call.&qu ...

  7. for update和for update nowait的区别和使用

    首先,for update 和for update nowait 是对操作的数据行进行加锁,在事务提交前防止其他操作对数据的修改. for update 和for update nowait主要区别在 ...

  8. Android Studio使用技巧

    1.ctrl+shift+F格式化代码时自动换行: 在settings里面找到Editor>General>Soft Wraps>设置选中Use soft wraps in edit ...

  9. Oracle的卸载与安装

    今天在做一个CURD的web小应用,为后面使用ExtJS搭建一个后台.因为还没有使用过Oracle数据库,因此今天也特的地的使用oracle数据库作为后台的数据库,也当练习使用oracle. 但是今天 ...

  10. 使用HTML+CSS,jQuery编写的简易计算器

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...