题目链接

有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. iOS开发-NSDictionary

    判断一个字典中是否存在某个key,有两种方法: 方法一: if ([dictionary allKeys] containsObject: key]){ // cotains key operatio ...

  2. spring applicationContext.xml 配置文件 详解

      <?xml version="1.0" encoding="UTF-8"?>   <beans xmlns="http://ww ...

  3. python+机器学习 算法用到的知识点总结

    1.浅述python中argsort()函数的用法 (1).先定义一个array数据 1 import numpy as np 2 x=np.array([1,4,3,-1,6,9]) (2).现在我 ...

  4. 【cs229-Lecture12】K-means算法

    上课内容: 无监督学习: K-means聚类算法 混合高斯模型 jensen不等式(用于推导出EM算法的一般形式) EM(Expectation Maximization)算法(最大期望算法) K-m ...

  5. Eclipse安装php插件phpeclipse(转)

    1.PHPEclipse是Eclipse的一个用于开发PHP的插件.官网下载地址:http://sourceforge.net/projects/phpeclipse/下载解压后,将features和 ...

  6. 【Spring Boot&& Spring Cloud系列】单点登录SSO概述

    概念 单点登录(Singleton Sign On),简称为SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应用系统中,用户只需要登录一次就能访问所有相互信任的应用系统. 也就 ...

  7. android 线程间的通信

    (转自:http://www.cnblogs.com/allin/archive/2010/05/19/1738800.html) andriod提供了 Handler 和 Looper 来满足线程间 ...

  8. cmake openssl ios

    1 下载源代码 git clone https://github.com/pol51/OpenSSL-CMake.git cd OpenSSL-CMake mkdir build && ...

  9. Android7.0 PowerManagerService 之亮灭屏(二) PMS 电源状态管理updatePowerStateLocked()

    本篇注意接着上篇[Android7.0 PowerManagerService 之亮灭屏(一)]继续分析量灭屏的流程,这篇主要分析PMS的状态计算和更新流程,也是PMS中最为重要和复杂的一部分电源状态 ...

  10. minix中二分查找bsearch的实现

    在看minix中bsearch实现的源代码之前,先学习一下C 语言中void类型以及void*类型的使用方法与技巧. void的含义: void的字面意思是“无类型”,void *则为“无类型指针”, ...