链接

算是裸线段树了,因为没个数最多开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. phpcms 内容模块PC标签调用

    PHPcms 调用命令的基本格式: 开始:{pc:content action="模块操作名" catid="调用栏目ID" num="数据调用数量& ...

  2. APTM敏捷性能测试模型

    随着应用系统的日趋复杂,仅在系统测试和验收测试阶段执行性能测试已经不能满足迟早发现和解决系统性能瓶颈的要求,Connie Smith博士和Lloyd Winlliams博士在他们提出 的软件性能工程( ...

  3. 运行swoole_server方法

    运行 php 文件 server.php 运行结果是如下: 只是服务器开启了 如果想看客户端连接的情况 可以测试一下 从新连接一个连接 用命令 方式 telnet 127.0.0.1 9501 这个9 ...

  4. C/C++获取Windows系统CPU和内存及硬盘使用情况

    //1.获取Windows系统内存使用率 //windows 内存 使用率 DWORD getWin_MemUsage(){ MEMORYSTATUS ms; ::GlobalMemoryStatus ...

  5. layui 复选框checkbox 全选写法

    前语:本来我是不想写layui框架的博客的,有的时候数据经过layui渲染后原生的写法就取不到值了,一定要用它框架的写法,实在蛋疼,故写之,以后用到可以省点时间去度娘! HTML: <div i ...

  6. java web 工程找不到tomcat类 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    ava.lang.ClassNotFoundException: com.mysql.jdbc.Driverat org.apache.catalina.loader.WebappClassLoade ...

  7. python数据分析笔记中panda(2)

    1 将手机号码分开为运营商,地区和号码段 from pandas import read_csv; df = read_csv("H:\\pythonCode\\4.6\\data.csv& ...

  8. Cpython 解释器下实现并发编程

    背景知识: 顾明思议: 进程即正在执行的一个过程,进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统, 是操作系统最核心的概念,也是操作系统提供的最古老的最重要的抽象概念之一.操作系统的其他所 ...

  9. HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】

    Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  10. jQuery 生成随机字符

    //获取长度为len的随机字母 //获取长度为len的随机字母 function zimu(len){ len = len || 1; var $chars = 'ABCDEFGHIJKLMNOPQR ...