链接

算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记。查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新。

注意用——int64

注意L会大于R 这点我很纠结。。您出题人故意的吗 WAn次。。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL __int64
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL s[N<<],f[N<<];
LL a[N];
void up(int w)
{
s[w] =s[w<<]+s[w<<|];
f[w] = (f[w<<]&&f[w<<|]);
}
void build(int l,int r,int w)
{
if(l==r)
{
s[w] = a[l];
if(a[l]==||a[l]==) f[w] = ;
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w);
}
void update(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
if(l==r)
{
LL k = sqrt(s[w]*1.0);
if(k*k>s[w])
k--;
s[w] = k;
if(s[w]<=)
f[w] = ;
// up(w);
return ;
}
if(f[w])
{
up(w);
return ;
}
else
{
int m = (l+r)>>;
if(a<=m)
update(a,b,l,m,w<<);
if(b>m)
update(a,b,m+,r,w<<|);
up(w);
return ;
}
}
int m = (l+r)>>;
if(a<=m)
update(a,b,l,m,w<<);
if(b>m)
update(a,b,m+,r,w<<|);
up(w);
}
LL query(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
int m = (l+r)>>;
LL res = ;
if(a<=m) res+=query(a,b,l,m,w<<);
if(b>m) res+=query(a,b,m+,r,w<<|);
return res;
}
int main()
{
int i,n,q;
int k,x,y,kk=;
while(scanf("%d",&n)!=EOF)
{
memset(f,,sizeof(f));
for(i = ; i <=n ;i++)
{
scanf("%I64d",&a[i]);
}
build(,n,);
scanf("%d",&q);
printf("Case #%d:\n",++kk);
while(q--)
{
scanf("%d%d%d",&k,&x,&y);
if(x>y) swap(x,y);
if(k)
{
printf("%I64d\n",query(x,y,,n,));
}
else
{
update(x,y,,n,);
}
}
puts("");
}
return ;
}

hdu4027Can you answer these queries?(线段树)的更多相关文章

  1. HDU-4027-Can you answer these queries?线段树+区间根号+剪枝

    传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...

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

  3. hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和

    Can you answer these queries? Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

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

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

  5. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  6. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  7. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

  8. 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? (线段树成段更新 && 开根操作 && 规律)

    题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...

随机推荐

  1. 如何查看智能手机的IP地址

      1.  外网IP IP地址可简单分为两类.外网IP或称公网IP是用来在Internet上唯一标识你的设备的.如果你通过GPRS或者3G技术接入互联网的话(通过运营商网络),那么你也可以通过下面的方 ...

  2. 为什要使用预编译SQL?

    今天在研发部技术大牛的指点下,我终于明白了为什么要使用SQL预编译的形式执行数据库JDBC:

  3. 百度地图API简单应用——1.根据地址查询经纬度

    这几天比较空闲,就接触了下百度地图的API(开发者中心链接地址:http://developer.baidu.com),发现调用还是挺方便的.只要简单几步注册下,就可以获得一个Key,就能直接调用(P ...

  4. [HAOI 2012] 外星人

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2749 [算法] 首先 , 每次对一个数x进行操作 , 只会使该数减少一个2的因子 那 ...

  5. HttpClient入门教程

    HttpClient使用详解与实战一:https://www.jianshu.com/p/375be5929bed

  6. iOS 中这些是否熟练掌握——(1)

    声明:本篇博文是作者原创作品.参考1  参考2  参考3  参考4  参考5  参考6 关于网上一些关于iOS资料,自己通过学习做了一些整理,这里仅仅作为笔记,方便自己学习使用,加深理解. 1.什么是 ...

  7. 转 vs2008使用技巧推荐

    Visual Studio 2008自带的1000多个 Windows 系统使用的各种图标.光标和动画文件在Visual Studio 2008的安装目录下,\Microsoft Visual Stu ...

  8. LeetCode: 496 Next Greater Element I(easy)

    题目: You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset ...

  9. vue中使用chart.js

    1,安装chart.js和vue-chart.js npm install chart.js --save npm install vue-chart.js --save 2,独立文件,方便修改 封装 ...

  10. qscoj53(图的m着色问题)

    题目链接:http://qscoj.cn/contest/12/problem/53/ 题意:中文题诶- 思路:n个点, 那么最多用n种颜色,所以我们可以枚举颜色种类1~n,然后再判断用 i 种颜色可 ...