http://acm.hdu.edu.cn/showproblem.php?pid=4027

/**
*  题意:给你n个数,对这些数进行操作,有m组操作
*        q == 0  [x,y]区间内的每个数开方
*        q == 1 输出[x,y]区间内的数的和
*  题解:线段树(简单的插线问线)注:当数更新到1后不再往下更新,即node[x].sum == r - l + 1,
*        不再往下更新了;
*  坑爹的c++输入输出,以后再也不能因为方便用了(无尽超时)
**/
code:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
#define lson(x) (x<<1)
#define rson(x) ((x<<1)|1)
#define M 5000100
struct Node{int l,r;LL sum;
}node[M*3];
void pushup(int x){node[x].sum = node[lson(x)].sum + node[rson(x)].sum;
}
void build(int l,int r,int x)
{node[x].l = l;node[x].r = r;if(l == r){scanf("%I64d",&node[x].sum);return ;}int mid = (l + r) >> 1;build(l,mid,lson(x));build(mid+1,r,rson(x));pushup(x);
}
void update(int l,int r,int x){if(node[x].r == r && node[x].l == l&&node[x].sum == r - l +1) return ;if(node[x].l == node[x].r) {node[x].sum = sqrt(node[x].sum*1.0);return ;}int mid = (node[x].l + node[x].r) >> 1;if(r <= mid) update(l,r,lson(x));else if(l > mid) update(l,r,rson(x));else {update(l,mid,lson(x));update(mid+1,r,rson(x));}pushup(x);
}
LL Query(int l,int r,int x){if(node[x].r == r && node[x].l == l) return node[x].sum;LL ans = 0;int mid = (node[x].l + node[x].r) >> 1;if(r <= mid) ans = Query(l,r,lson(x));else if(l > mid) ans = Query(l,r,rson(x));else {ans += Query(l,mid,lson(x));ans += Query(mid+1,r,rson(x));}return ans;
}
int main(){int n,m,q,x,y,ca = 1;while(scanf("%d",&n)!=EOF){build(1,n,1);scanf("%d",&m);printf("Case #%d:\n",ca++);for(int i = 0;i < m;i++){scanf("%d%d%d",&q,&x,&y);if(x > y) swap(x,y);if(q == 0)update(x,y,1);elseprintf("%I64d\n",Query(x,y,1));}printf("\n");}return 0;
}

hdu - 4027 Can you answer these queries?相关推荐

  1. HDU 4027 Can you answer these queries?(线段树/区间不等更新)

    传送门 Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/6576 ...

  2. hdu 4027 Can you answer these queries?

    http://acm.hdu.edu.cn/showproblem.php?pid=4027 [更新区间,查询区间]的线段树,必须抓住修改6次以后每个数必然会变成1,然后以后的修改都将不起作用,在此之 ...

  3. HDU - 4027 Can you answer these queries?(线段树)

    题目链接:点击查看 题目大意:给定n艘敌军的舰队,每艘舰队都有一定的耐力值,随后进行m次操作,共包括两种操作,分别是输出区间[l,r]中的耐力 值之和,以及将区间[l,r]中的每个的耐力值都开平方 题 ...

  4. HDU 1027 G - Can you answer these queries?

    http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Time Limit: 4000/2000 M ...

  5. HDU - 4027

    Can you answer these queries? 链 接 链接 链接 HDU - 4027 题 目 是 区 间 修 改 区 间 查 询 , 但 是 区 间 开 根 号 , 求 区 间 和 题 ...

  6. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

  7. 线性代数四之动态DP(广义矩阵加速)——Can you answer these queries III,保卫王国

    动态DP--广义矩阵加速 SP1716 GSS3 - Can you answer these queries III description solution code [NOIP2018 提高组] ...

  8. SPOJ GSS2 Can you answer these queries II (线段树离线) - xgtao -

    Can you answer these queries II 这是一道线段树的题目,维护历史版本,给出N(<=100000)个数字(-100000<=x<=100000),要求求出 ...

  9. GSS2 - Can you answer these queries II

    GSS2 - Can you answer these queries II 题意: 给你1e51e51e5 的序列,每次询问区间l到rl到rl到r,每个相同的数只算一次的最大子段和. 思路: 乍一眼 ...

最新文章

  1. withRouter组件
  2. oracle何时使用to_date函数
  3. Swoole练习 Web
  4. GitHub user guide:Hello world
  5. Linux下让进程在后台可靠运行的几种方法
  6. 【深度学习】PyTorch 历史版本安装-祖传老代码运行刚需
  7. 《大型网站技术架构:核心原理与案例分析》笔记05
  8. linux脚本文件个数,Linux上面执行mysql脚本判断文件个数
  9. Redis 集群搭建和简单使用
  10. 将 .NET Framework 项目转换为 .NET Standard 项目
  11. 从客户端...中检测到有潜在危险的 Request.Form 值
  12. 新手如何准确的控制油门
  13. 二分法查找 - python实现
  14. vue 打包之后不兼容ie_vue中使用的一些问题(IE不兼容,打包样式不生效)
  15. Python 获取 网卡 MAC 地址
  16. OpenCV-绘制箭头cv::arrowedLine
  17. SpringBoot配置RunDashboard
  18. linux常用命令之文件操作
  19. 医学统计学傻瓜教程(2019版)*
  20. 人工智能是怎么用在人脸识别上的?

热门文章

  1. git 命令行使用(基础篇)
  2. 德国Renusol进军南非市场 瞄准屋顶光伏
  3. [转]android之Apache Http——向服务器发送请求的同时发送参数
  4. 设计模式之四(抽象工厂模式第一回合)
  5. EIGRP Metric计算
  6. tenjin - 号称全球最快的模板引擎
  7. 游戏编程入门(1) -- 精灵 ISprite
  8. 基于便签纸的无限延生学习方法
  9. 哥大计算机工程申请入口和登陆入口
  10. 《Unity虚拟现实开发实战》——第1章,第1.8节小结