题目

线段树

简单题意:

区间(单点?)更新,区间求和

 更新是区间内的数开根号并向下取整

这道题不用延迟操作

//注意:
//1:查询时的区间端点可能前面的比后面的大;
//2:优化:因为每次更新都是开平方,同一个数更新有限次数就一直是1了,所以可以这样优化
#include <stdio.h>
#include<math.h>
#define N 100010 #define LL __int64
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 LL sum[N<<]; void PushUP(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
} void Build(int l,int r,int rt)
{
if(l==r)
{
scanf("%I64d",&sum[rt]);
return;
}
int m=(l+r)>>;
Build(lson);
Build(rson);
PushUP(rt);
} void Update(int L,int R,int l,int r,int rt)
{ if(l==r)
{
sum[rt]=(__int64)sqrt((double)sum[rt]);
return;
}
int m=(l+r)>>;
if(L<=m)
Update(L,R,lson);
if(R>m)
Update(L,R,rson);
PushUP(rt);
} LL Query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
return sum[rt];
int m=(l+r)>>;
LL ret=;
if(L<=m) ret+=Query(L,R,lson);
if(R>m) ret+=Query(L,R,rson);
return ret;
} int main()
{
int m,n,id=;
LL anss;
while(scanf("%d",&n)!=EOF)
{
Build(,n,);
scanf("%d",&m);
printf("Case #%d:\n",id++);
while(m--)
{
int q,a,b,c;
scanf("%d%d%d",&q,&a,&b);
if(a>b)
{
c=a;
a=b;
b=c;
} anss=Query(a,b,,n,);
if(q==)
{
printf("%I64d\n",anss);
}
else
{
if(anss != b-a+)
Update(a,b,,n,);
}
}
printf("\n");
}
return ;
}

虽然我自己不会写线段树,但是以后遇到 区间(单点?)更新,区间求和,这可以当底板修改一下就可以用了,毕竟这里的用法还是蛮好理解的

HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)的更多相关文章

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

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

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

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

  4. HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)

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

  5. A Simple Problem with Integers 线段树 区间更新 区间查询

    Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 115624   Accepted: 35897 Case Time Lim ...

  6. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  7. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  8. codevs 1690 开关灯 线段树区间更新 区间查询Lazy

    题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这些路灯全是关着的,六点之后,会有M(2<=m<=100000)个人 ...

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

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

随机推荐

  1. WPF工作笔记:本地化支持、主进程通知、两种最常用异步编程方式

    1.本地化支持 (1)重写控件默认的依赖属性LanguageProperty FrameworkElement.LanguageProperty.OverrideMetadata( typeof(Fr ...

  2. 普通委托到泛型委托到Linq

    private delegate bool delTest(int a); private void button1_Click(object sender, EventArgs e) { var a ...

  3. 内核同步机制 RCU

    Evernote分享地址:http://www.evernote.com/shard/s133/sh/8807320d-f54d-4e90-a31b-e2a3d35509ee/7539dc3931b8 ...

  4. spring与mysql整合数据源的配置

    需要解决两点,数据源的配置交给spring完成,事务管理交个spring来管理. <context:property-placeholder location="classpath:c ...

  5. Windows Phone动画

    从事Windows Phone开发已经有一段时间了,但是一直没有好好的静下心来梳理一下自己这段时间的知识,一是怕自己学问不到家,写不出那些大牛一般的高屋建瓴:二是以 前一直没有写博客的习惯:好了废话不 ...

  6. Xcode全局断点

    1.将导航器视图切换到断点导航器视图下,也可以用快捷键Command+7一步搞定,键盘是window风格的用户Command键是win键(有微软logo),然后点击左下角的+号,选择Add Symbo ...

  7. mysql字段累加concat

    update tablename set field1=concat(field1,'_bak') where field2 like '%@xxx’

  8. scjp考试准备 - 3 - 关于Arrays

    判断如下程序的最终输出值: import java.util.*; public class Quest{ public static void main(String[] args){ String ...

  9. 将商户后台_门店管理后台_平台后台管理v1.0 Axure RP项目上传到svn服务器步骤

  10. [转]webrtc学习: 部署stun和turn服务器

    [转]webrtc学习: 部署stun和turn服务器 http://www.cnblogs.com/lingdhox/p/4209659.html webrtc的P2P穿透部分是由libjingle ...