题意:

      给你n个数(n <= 100000),然后两种操作,0 x y :把x-y的数全都sqrt ,1 x y:输出 x-y的和。



思路:

      直接线段树更新就行了,对于当前的这个区间,如果里面只有0或者1,那么就把他mark上,以后不用在更新了,10^18 更新不了多少次就会变成0或者1的,所以时间复杂度也没多少,每次更新能返回就返回,不能返回就一定要精确到点,然后sqrt,然后查询的话就是一个简单的段询问。


#include<stdio.h>

#include<string.h>

#include<math.h>

#define lson l ,mid ,t << 1

#define rson mid + 1 ,r ,t << 1 | 1

long long  sum[440000];

long long mark[440000];

void Pushup(int t)

{

   sum[t] = sum[t<<1] + sum[t<<1|1];

   mark[t] = (mark[t<<1] & mark[t<<1|1]);

}

void BuidTree(int l ,int r ,int t)

{

   mark[t] = sum[t] = 0;

   if(l == r)

   {

      scanf("%lld" ,&sum[t]);

      if(sum[t] == 0 || sum[t] == 1)

      mark[t] = 1;

      return;

   }

   int mid = (l + r) >> 1;

   BuidTree(lson);

   BuidTree(rson);

   Pushup(t);

   return;

}

 

void Update(int l ,int r ,int t ,int a ,int b)

{

   if(mark[t]) return;

   if(l == r)

   {

      sum[t] = (long long)sqrt(sum[t]*1.0);

      if(sum[t] == 1 || sum[t] == 0) mark[t] = 1;

      return;

   }

   int mid = (l + r) >> 1;

   if(a <= mid) Update(lson ,a ,b);

   if(b > mid)  Update(rson ,a ,b);

   Pushup(t);

}

long long Query(int l ,int r ,int t ,int a ,int b)

{

   if(a <= l && b >= r) return sum[t];

   int mid = (l + r) >> 1;

   long long Ans = 0;

   if(a <= mid) Ans = Query(lson ,a ,b);

   if(b > mid) Ans += Query(rson ,a ,b);

   return Ans;

}

int main ()

{

   int i ,n ,m ,cas = 1;

   int key ,a ,b;

   while(~scanf("%d" ,&n))

   {

      BuidTree(1 ,n ,1);

      scanf("%d" ,&m);

      printf("Case #%d:\n" ,cas ++);

      while(m--)

      {

         scanf("%d %d %d" ,&key ,&a ,&b);

         int t;

         if(a > b) 

         {

            t = a ,a = b ,b = t;

         } 

         if(!key)

         {

            Update(1 ,n ,1 ,a ,b);

         }

         else

         {

            printf("%lld\n" ,Query(1 ,n ,1 ,a ,b));

         }

      }

      printf("\n");

   }

   return 0;

}

SPOJ 2713 线段树(sqrt)的更多相关文章

  1. SPOJ GSS3 线段树系列1

    SPOJ GSS系列真是有毒啊! 立志刷完,把线段树搞完! 来自lydrainbowcat线段树上的一道例题.(所以解法参考了lyd老师) 题意翻译 n 个数, q 次操作 操作0 x y把 Ax 修 ...

  2. SPOJ - GSS1 —— 线段树 (结点信息合并)

    题目链接:https://vjudge.net/problem/SPOJ-GSS1 GSS1 - Can you answer these queries I #tree You are given ...

  3. SPOJ COT3 Combat on a tree(Trie树、线段树的合并)

    题目链接:http://www.spoj.com/problems/COT3/ Alice and Bob are playing a game on a tree of n nodes.Each n ...

  4. SPOJ 2916 Can you answer these queries V(线段树-分类讨论)

    题目链接:http://www.spoj.com/problems/GSS5/ 题意:给出一个数列.每次查询最大子段和Sum[i,j],其中i和j满足x1<=i<=y1,x2<=j& ...

  5. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  6. SPOJ 1557. Can you answer these queries II 线段树

    Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/pr ...

  7. bzoj 2482: [Spoj GSS2] Can you answer these queries II 线段树

    2482: [Spoj1557] Can you answer these queries II Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 145 ...

  8. spoj gss2 : Can you answer these queries II 离线&&线段树

    1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...

  9. SPOJ GSS1_Can you answer these queries I(线段树区间合并)

    SPOJ GSS1_Can you answer these queries I(线段树区间合并) 标签(空格分隔): 线段树区间合并 题目链接 GSS1 - Can you answer these ...

随机推荐

  1. 树莓派4刷FreeBSD

    树莓派4可以刷FreeBSD了.需要替换boot文件.​加群获得文件QQ交流群817507910.

  2. 【odoo14】第十四章、CMS网站开发

    第十四章.CMS网站开发** Odoo有一个功能齐全的内容管理系统(CMS).通过拖放功能,你的最终用户可以在几分钟内设计一个页面,但是在Odoo CMS中开发一个新功能或构建块就不是那么简单了.在本 ...

  3. Asa's Chess Problem

    一.题目 给定一张 \(n\times n\) 的矩阵,每个点上面有黑棋或者是白棋,给定 \(\frac{n\times n}{2}\) 对可以交换的位置,每对位置一定在同一行 \(/\) 同一列.\ ...

  4. python的类的实际联系--烤地瓜和搬家具

    #coding:utf-8 2 class SweetPotato(): 3 def __init__(self): 4 #先初始化对象 5 self.cook_time = 0 6 self.coo ...

  5. 高精地图技术专栏 | 基于空间连续性的异常3D点云修复技术

    1.背景 1.1 高精资料采集 高精采集车是集成了测绘激光.高性能惯导.高分辨率相机等传感器为一体的移动测绘系统.高德高精团队经过多年深耕打造的采集车,具有精度高.速度快.数据产生周期短.自动化程度高 ...

  6. POJ2635(数论+欧拉筛+大数除法)

    题目链接:https://vjudge.net/problem/POJ-2635 题意:给定一个由两个质数积的大数M和一个数L,问大数M的其中较小的质数是否小于L. 题解:因为大数M已经超过long ...

  7. sqli-labs系列——第五关

    less5 更改id后无果,不能用union联合查询 此处用报错注入 报错注入的概念:(1). 通过floor报错 and (select 1 from (select count(*),concat ...

  8. 写个小程序01 | 注册微信小程序

    出于兴趣和学习目的,我想自己做一个基于"子弹笔记(Bullet Journal)"的小程序.由于个人开发经验很有限,只在课程作业中写过 web 前端,所以也不知道多久能写出来(逃) ...

  9. 【linux】驱动-11-gpio子系统

    目录 前言 11. gpio子系统 11.1 操作步骤 11.1.1 新版 API 操作流程 11.1.2 旧版 API 操作流程 11.2 设备树中使用gpio子系统 11.3 GPIO 子系统 A ...

  10. 京东效率专家带你快速落地DevOps

    行业内的公司纷纷在招聘DevOps工程师,企业的DevOps转型看起来迫在眉睫,公司内部也要设计和开发DevOps平台,DevOps已经成为了所有IT从业人员应知应会的必备技能. 为你提供一套清晰的D ...