题目链接:点击打开链接

题意:

给定n长的序列

以下2个操作

0 x y 给[x,y]区间每一个数都 sqrt

1 x y 问[x, y] 区间和

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <math.h>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define N 100005
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
#define Num(x) tree[x].num
#define Sum(x) tree[x].sum
inline int Mid(int x, int y){return (x+y)>>1;}
struct Subtree{int l, r;ll num, sum;
}tree[N<<2];
ll a[N];
void push_up(int id){if(L(id) == R(id))return;Sum(id) = Sum(Lson(id)) + Sum(Rson(id));if(Num(Lson(id)) <= 1  && Num(Rson(id)) <= 1)Num(id) = 1;else Num(id) = 2;
}
void build(int l, int r, int id){L(id) = l; R(id) = r;if(l == r) { Num(id) = Sum(id) = a[l]; return ;}int mid = Mid(l, r);build(l, mid, Lson(id));build(mid+1, r, Rson(id));push_up(id);
}
void updata(int l, int r, int id){if(L(id) == R(id)){Sum(id) = Num(id) = (ll)sqrt((double)Sum(id));return ;}if(l == L(id) && R(id) == r && Num(id) <= 1) return ;int mid = Mid(L(id), R(id));if(mid < l)updata(l, r, Rson(id));else if(r <= mid)updata(l, r, Lson(id));else {updata(l, mid, Lson(id));updata(mid+1, r, Rson(id));}push_up(id);
}
ll query(int l, int r, int id){if(l == L(id) && R(id) == r)return Sum(id);int mid = Mid(L(id), R(id));if(mid < l)return query(l, r, Rson(id));else if(r <= mid)return query(l, r, Lson(id));else return query(l, mid, Lson(id)) + query(mid+1, r, Rson(id));
}
int n;
void solve(){int q, op, x, y;for(int i = 1; i <= n; i++)scanf("%lld", &a[i]);build(1, n, 1);scanf("%d",&q);while(q--){scanf("%d %d %d", &op, &x, &y);if(x > y) swap(x, y);if(op == 0)updata(x, y, 1);elseprintf("%lld\n", query(x, y, 1));}
}
int main(){int Cas = 1;while(~scanf("%d", &n)){printf("Case #%d:\n", Cas++);solve();puts("");}return 0;
}
本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5198479.html,如需转载请自行联系原作者

Spoj 2713 Can you answer these queries IV 水线段树相关推荐

  1. 【线段树】 SPOJ 2713 Can you answer these queries IV

    更新操作:一段区间内的全部数开根号 查询操作:一段区间内的sum值 在一个值更新操作十几次之后会变成 1 之后就不需要再更新这段了 所以在update 某个区间 r-l+1==sum[rt] j就re ...

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

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

  3. 【SPOJ】2713 Can you answer these queries IV

    操作: 1,把[x,y]每个数k变成sqrt(k),向下取整. 2,查询区间的和. 就算10^18,sqrt后减少的很快. 当一个数为0或1时,它不会再变化了,把不会变化的区间标记,不再访问. 所以暴 ...

  4. SP1043 GSS1 - Can you answer these queries I(线段树,区间最大子段和(静态))

    题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义如下: 查询(x,y)=max{a[i]+a[i+1]+...+a[j]:x≤i≤j≤y} ...

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

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

  6. Codeforces 1114F Please, another Queries on Array? 线段树

    Please, another Queries on Array? 利用欧拉函数的计算方法, 用线段树搞一搞就好啦. #include<bits/stdc++.h> #define LL ...

  7. spoj 2916. Can you answer these queries V(线段树)

    题目链接:http://www.spoj.com/problems/GSS5/ 题意:给出n个数,求区间最大子段和,但是限制了子段的起点终点,起点要在[x1,y1]内,终点要在[x2,y2]内. 思路 ...

  8. 解题报告:SP2713 GSS4 - Can you answer these queries IV(GSS线段树八部曲之四)

    x>yx>yx>y是真的艹. 然后就是一道模板题了. #include<bits/stdc++.h>using namespace std; typedef long l ...

  9. [SPOJ] 1043 Can you answer these queries I [GSS1]

    Pro 给你一个序列{A[1], A[2], ..., A[N]}.( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ) 给定"查询"操作的定义如下: Query( ...

  10. SPOJ - GSS3 Can you answer these queries III(线段树+区间合并)

    题目链接:点击查看 题目大意:给出一个长度为n的序列,进行m次操作: 1 x y  查询区间[l,r]中的最大连续子段和 0 x y  将第x个数修改为y 题目分析:因为涉及到单点修改和区间查询等操作 ...

最新文章

  1. CoTNet-重磅开源!京东AI Research提出新的主干网络CoTNet,在CVPR上获得开放域图像识别竞赛冠军
  2. ckeditor3 在Asp.net MVC2.0环境中的配置
  3. 正则表达式实现手机号中间4位数隐藏或者只显示末尾四位数
  4. 谈谈怎样提高炼丹手速
  5. empinfo Oracle数据库,Oracle数据库---包
  6. shell脚本spawn_如何使用child_process.spawn将Python / Ruby / PHP Shell脚本与Node.js集成
  7. 一个XML Schema及XML文档(联系人)
  8. 【人工智能】【深度学习】初学者如何选出最适合自己深度学习框架?
  9. dedecms php5.4 无法退出后台,DedeCMS 织梦在 Windows 的 PHP5.4 环境下登录后台空白的解决办法...
  10. 小米MIX4不会采用四曲面屏:结果未必是坏事
  11. 多媒体台式计算机安装方法,台式机如何组装 台式机组装注意事项【详解】
  12. Android SELinux avc denied解决
  13. autojs之快捷键
  14. KITTI数据集可视化
  15. 用域代码任何带圈字符都能做出来
  16. Git代码提交,固定日志模板
  17. 拼多多sdk php,标签PHP拼多多SDK文章 - 零分博客 - 关注互联网且乱扯淡互联网的个人博客...
  18. NVIDIA显卡驱动重装
  19. Hive ANALYZE NOSCAN
  20. 【已解决】The server cannot or will not process the request due to something that is perceived to be ...

热门文章

  1. [Unity Mirror] SyncVars
  2. 2022年山东省安全员B证判断题及答案
  3. eclipse使用SVN进行同步时,发生错误的解决办法
  4. Matlab 画出不同位置高度的圆柱--样例二
  5. 如何实现随机漂浮气球
  6. 舞蹈健身房私人教练响应式网站模板
  7. 玄子BCSP-MySQL 5.7.40 压缩包安装教程(含下载链接)
  8. 谢希仁计算机网络第6版教材精讲考研真题串讲视频
  9. 【用unity实现100个游戏之14】Unity2d做一个建造与防御类rts游戏(附项目源码)
  10. 5个内容 击败谷歌企鹅更新