【题目分析】

区间开方+区间求和。

由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可。

这不是BZOJ上上帝造题7分钟嘛

【代码】

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. #define ll long long
  7. using namespace std;
  8. long long a[100001],f[100001],n,q,op,l,r;
  9. long long t[100001];
  10. inline long long gf(long long k)
  11. {
  12. if (f[k]==k) return k;
  13. else return f[k]=gf(f[k]);
  14. }
  15. inline void add(long long x,long long f)
  16. {
  17. for (;x<=n;x+=x&(-x))
  18. t[x]+=(ll)f;
  19. }
  20. inline long long gs(long long x)
  21. {
  22. long long ret=0;
  23. for (;x;x-=x&(-x)) ret+=t[x];
  24. return ret;
  25. }
  26. int main()
  27. {
  28. int kas=0;
  29. while (scanf("%lld",&n)!=EOF)
  30. {
  31. printf("Case #%d:\n",++kas);
  32. memset(t,0,sizeof t);
  33. for (long long i=1;i<=n;++i) scanf("%lld",&a[i]),f[i]=i;
  34. f[n+1]=n+1;
  35. for (long long i=1;i<=n;++i) add(i,a[i]);
  36. scanf("%lld",&q);
  37. for (long long zz=1;zz<=q;++zz)
  38. {
  39. scanf("%lld",&op);
  40. if (op==0)
  41. {
  42. scanf("%lld%lld",&l,&r);
  43. if (l>r) swap(l,r);
  44. long long i=l;
  45. while (i<=r)
  46. {
  47. i=gf(f[i]);
  48. if (i>r) break;
  49. long long tmp=a[i];
  50. a[i]=(long long)sqrt(a[i]);
  51. add(i,a[i]-tmp);
  52. if (a[i]==1) f[i]=f[i]+1;
  53. gf(f[i]);
  54. i++;
  55. }
  56. }
  57. else
  58. {
  59. scanf("%lld%lld",&l,&r);
  60. if (l>r) swap(l,r);
  61. printf("%lld\n",gs(r)-gs(l-1));
  62. }
  63. }
  64. printf("\n");
  65. }
  66. }

  

SPOJ GSS4 Can you answer these queries IV ——树状数组 并查集的更多相关文章

  1. SPOJ GSS4 Can you answer these queries IV

    Time Limit: 500MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

  2. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  3. 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国

    SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...

  4. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  5. SP2713 GSS4 - Can you answer these queries IV(线段树)

    传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...

  6. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

  7. CodeForces - 369E Valera and Queries(树状数组)

    CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...

  8. 题解【SP2713】GSS4 - Can you answer these queries IV

    题目描述 You are given a sequence \(A\) of \(N(N \leq 100,000)\) positive integers. There sum will be le ...

  9. Spoj 2713 Can you answer these queries IV 水线段树

    题目链接:点击打开链接 题意: 给定n长的序列 以下2个操作 0 x y 给[x,y]区间每一个数都 sqrt 1 x y 问[x, y] 区间和 #include <stdio.h> # ...

随机推荐

  1. Azure Linux 云主机使用Root超级用户登录

    Azure的Linux虚拟机是可以灵活使用root超级用户的管理员权限的: 1:使用sudo passwd root指令设置超级用户root密码: 使用创建Linux时设置的用户名和密码登陆,使用su ...

  2. github入门之配置github本地仓库--2

    *前期准备工作 创建github账户 github地址 1.设置SSH_Key ssh-keygen -t rsa -C "你的邮箱" 2.查看秘钥 cat ~/.ssh/id_r ...

  3. 反射机制与IOC容器

    原文地址:http://blog.csdn.net/u010926964/article/details/47262771

  4. Maven归纳

      一.常用功能 1.Maven的中央仓库 https://mvnrepository.com/ 2.添加jar包依赖 1.首先点击pom.xml,然后点击弹出页面中的Dependencies选项,接 ...

  5. java第九次作业:第九章例题3个

    作业1: 例题9.1 制作圆类,根据圆的半径求出周长及面积 package com.swift; //抽象的方法构成类,把属性和方法进行封装 public class Circle { // 两个方面 ...

  6. [LUOGU] P1551 亲戚

    题目背景 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 题目描述 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如 ...

  7. Linux内核 ——进程管理之进程诞生(基于版本4.x)

    <奔跑吧linux内核>3.1笔记,不足之处还望大家批评指正 进程是Linux内核最基本的抽象之一,它是处于执行期的程序.它不仅局限于一段可执行代码(代码段),还包括进程需要的其他资源.在 ...

  8. 重置windows用户漫游配置文件

    1.备份用户数据 2.删除或修改漫游配置文件 3.用户PC管理员登陆,删除本地用户缓存文件 注册表打开: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows N ...

  9. 如何用纯 CSS 创作一个雷达扫描动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/VdbGvr 可交互视频 ...

  10. jsDate()

    var myTime=new Date();//myTime的数据类型为(typeof) object //下面得到的都为number 类型 getFullYear();年 四位数字返回年份. get ...