题目链接

有n个数:当操作为1时求L到R的和;

当操作为0时更新L到R为原来的平方根;

不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底。、

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#define INF 0xfffffff
#define N 100010
using namespace std; #define Lson r<<1
#define Rson r<<1|1 struct SegTree
{
int L, R;
long long sum;
int mid()
{
return (L+R)>>;
}
int len()
{
return R-L+;
}
}a[N*]; void Update(int r, int L, int R)
{
if(a[r].len()==a[r].sum)
return ;
if(a[r].L == a[r].R)//到达叶子节点;
{
a[r].sum = (long long)sqrt(a[r].sum);
return ;
}
if(R<=a[r].mid())
Update(Lson, L, R);
else if(L > a[r].mid())
Update(Rson, L, R);
else
{
Update(Lson, L, a[r].mid());
Update(Rson, a[r].mid()+, R);
}
a[r].sum = a[Rson].sum + a[Lson].sum;
} void BuildSegTree(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
if(L == R)
{
scanf("%I64d", &a[r].sum);
return;
}
BuildSegTree(Lson, L, a[r].mid());
BuildSegTree(Rson, a[r].mid()+, R); a[r].sum = a[Rson].sum + a[Lson].sum;
}
long long Query(int r, int L, int R)
{
if(a[r].L == L && a[r].R == R)
{
return a[r].sum;
}
if(L>a[r].mid())
return Query(Rson, L ,R);
else if(R <= a[r].mid())
return Query(Lson, L, R);
else
{
long long ans1 = Query(Lson, L, a[r].mid());
long long ans2 = Query(Rson, a[r].mid()+, R);
return ans1 + ans2;
}
}
int main()
{
int n, m, L, R, op, t=;
while(scanf("%d", &n) != EOF)
{
BuildSegTree(, , n);
scanf("%d", &m);
printf("Case #%d:\n", t++);
while(m--)
{
scanf("%d%d%d", &op, &L, &R);
if(L>R)swap(L, R);//L和R的大小没说;
if(op==)
Update(, L, R);
else
{
long long ans=Query(, L, R);
printf("%I64d\n", ans);
}
}
printf("\n");
}
return ;
}

Can you answer these queries?---hdu4027的更多相关文章

  1. (线段树 区间查询更新) Can you answer these queries? -- hdu--4027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...

  2. Can you answer these queries?-HDU4027 区间开方

    题意: 给你n个数,两个操作,0为区间开方,1为区间求和 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 思路: 如果当该区间的数都为1,我们没必要 ...

  3. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

  4. 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 ...

  5. 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 ...

  6. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  7. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

  8. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  9. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

随机推荐

  1. CM和CDH的安装-准备工作

    估计要分开来两篇博客说明,因为截图较多. 1.三个节点cdh1(主节点),cdh2,cdh3 配置就用一张图来说明,因为资源有限 2.版本依赖说明: CDH-5.9.0-1.cdh5.9.0.p0.2 ...

  2. sql 替换字符串

    MSSQL替换语句: )),'abc.com','123.com') 例如: update PE_Article set Content=replace(cast(Content as varchar ...

  3. HttpClient(三)-- 抓取图片

    使用HttpClient抓取图片,先通过 entity.getContent() 获取输入流,然后 使用 common io 中的文件复制 方法 将图片专区到本地,代码如下: 1.需要依赖common ...

  4. 几种Bean的复制方法性能比较

    由于项目对性能 速度要求很高,表中的字段也很多,存在一个复制方法,耗时相对比较长,经过测试,使用Apache,Spring等提供的方法 耗时较长,使用自己自定义的复制方法时间提升很多,现记录下. 1. ...

  5. 使用 urllib 处理 Cookies 信息

    如何获取 Cookies : import urllib.request import http.cookiejar cookies = http.cookiejar.CookieJar() # 先声 ...

  6. Excel 导入遍历

    package com.founder.ec.cms.service.impl; import com.founder.ec.cms.service.ProductListImportService; ...

  7. C语言char*字符串数组和unsigned char[]数组的相互转换

    #include <iostream> #include <string> using namespace std; void convertUnCharToStr(char* ...

  8. U盘安装centos6.4:缺少iso 9660映像

    方法: 1.下载安装的ISO文件    到www.centos.org网站下载对应的Centos 6.4安装文件.下载站点我一般选择网易镜像站点    64位下载参考链接:http://mirrors ...

  9. <转>github入门到上传本地项目

    转自 http://www.cnblogs.com/specter45/p/github.html GitHub是基于git实现的代码托管.git是目前最好用的版本控制系统了,非常受欢迎,比之svn更 ...

  10. 【python3】window下 vscode 配置 python3开发环境

    本文以python3.7 为例 一 下载python3 url : https://www.python.org/downloads/windows/ 提示: 安装过程中.记得勾选  添加环境变量 二 ...