A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon, it could decrease the endurance of a consecutive part of battleships by make their endurance to the square root of it original value of endurance. During the series of attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you for help.
You are asked to answer the queries that the sum of the endurance of a consecutive part of the battleship line.

Notice that the square root operation should be rounded down to integer.

InputThe input contains several test cases, terminated by EOF.

  For each test case, the first line contains a single integer N, denoting there are N battleships of evil in a line. (1 <= N <= 100000)

  The second line contains N integers Ei, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 2
63.

  The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000)

  For the following M lines, each line contains three integers T, X and Y. The T=0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. The T=1 denoting the query of the commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.

OutputFor each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.Sample Input

  1. 10
  2. 1 2 3 4 5 6 7 8 9 10
  3. 5
  4. 0 1 10
  5. 1 1 10
  6. 1 1 5
  7. 0 5 8
  8. 1 4 8

Sample Output

  1. Case #1:
  2. 19
  3. 7
  4. 6
  5.  
  6. 这道题目测区间修改,但是不像加或减,开方不好处理,但是发现一个数开7 8次就变为1了,所以可以修改叶节点,然后求和就可以了。如果区间全是1,就不需要往下更新了
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <string>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <sstream>
  13. #include <stack>
  14. using namespace std;
  15. #define FO freopen("in.txt","r",stdin);
  16. #define rep(i,a,n) for (int i=a;i<n;i++)
  17. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  18. #define pb push_back
  19. #define mp make_pair
  20. #define all(x) (x).begin(),(x).end()
  21. #define fi first
  22. #define se second
  23. #define SZ(x) ((int)(x).size())
  24. #define debug(x) cout << "&&" << x << "&&" << endl;
  25. #define lowbit(x) (x&-x)
  26. #define mem(a,b) memset(a, b, sizeof(a));
  27. typedef vector<int> VI;
  28. typedef long long ll;
  29. typedef pair<int,int> PII;
  30. const ll mod=;
  31. const int inf = 0x3f3f3f3f;
  32. ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
  33. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  34. //head
  35.  
  36. const int maxn=;
  37. ll sum[maxn<<];
  38. int n,q;
  39.  
  40. void pushup(int rt) {
  41. sum[rt]=sum[rt<<]+sum[rt<<|];
  42. }
  43.  
  44. void build(int rt,int L,int R) {
  45. if(L==R) {
  46. scanf("%lld",&sum[rt]);
  47. return;
  48. }
  49. int mid=(L+R)>>;
  50. build(rt<<,L,mid);
  51. build(rt<<|,mid+,R);
  52. pushup(rt);
  53. }
  54.  
  55. void updata(int rt,int L,int R,int l,int r) {
  56. if(L==R) {
  57. sum[rt]=sqrt(sum[rt]);
  58. return;
  59. }
  60. if(L>=l&&R<=r&&sum[rt]==(R-L+)) return;
  61. int mid=(L+R)>>;
  62. if(l<=mid) updata(rt<<,L,mid,l,r);
  63. if(r>mid) updata(rt<<|,mid+,R,l,r);
  64. pushup(rt);
  65. }
  66.  
  67. ll query(int rt,int L,int R,int l,int r) {
  68. if(L>=l&&R<=r) return sum[rt];
  69. ll ans=;
  70. int mid=(L+R)>>;
  71. if(l<=mid) ans+=query(rt<<,L,mid,l,r);
  72. if(r>mid) ans+=query(rt<<|,mid+,R,l,r);
  73. pushup(rt);
  74. return ans;
  75. }
  76.  
  77. int main() {
  78. int cur=;
  79. while(~scanf("%d",&n)) {
  80. build(,,n);
  81. scanf("%d",&q);
  82. int op,ll,rr;
  83. printf("Case #%d:\n",cur++);
  84. while(q--) {
  85. scanf("%d%d%d",&op,&ll,&rr);
  86. int l=min(ll,rr),r=max(ll,rr);
  87. if(op) printf("%lld\n",query(,,n,l,r));
  88. else updata(,,n,l,r);
  89. }
  90. printf("\n");
  91. }
  92. }
  1.  

kuangbin专题七 HDU4027 Can you answer these queries? (线段树)的更多相关文章

  1. kuangbin专题七 HDU1540 Tunnel Warfare (前缀后缀线段树)

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast a ...

  2. kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)

    Painting some colored segments on a line, some previously painted segments may be covered by some th ...

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

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

  4. HDU4027 Can you answer these queries?(线段树 单点修改)

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  5. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

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

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

  8. HDU-4027-Can you answer these queries?线段树+区间根号+剪枝

    传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...

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

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

随机推荐

  1. java 字符串和集合互相转换

    今天在写项目的时候遇到一个问题,就是要把得到的一个集合转换成字符串,发现 import org.apache.commons.lang.StringUtils; 有这么一个简单的方法:String s ...

  2. Linux 压缩文件 和解压文件

    .zip 解压:unzip FileName.zip 压缩:zip FileName.zip DirName .rar 解压:rar -x FileName.zip 压缩:rar -a FileNam ...

  3. linux进程的软中断通信

    linux进程的软中断通信 要求 实现软中断通信的程序 使用系统调用fork()创建两个子进程,再用系统调用signal()让父进程捕捉键盘上发出的中断信号(即按delete键),当父进程接收到这两个 ...

  4. vue 跨域访问http

    axios用法: npm install axios --save-dev 2.导入: import axios from 'axios'; 3.使用($(form)需要先按装jQuery) axio ...

  5. WDCP文件缓存问题

    WDCP文件缓存问题,新建index.php 输入代码 <?php echo '789'; ?> 显示789 修改代码 <?php echo '666'; ?> 显示789 访 ...

  6. Edison UVALive3488

    传送门 题目大意 有一个0~n-1的序列,有m次操作,操作包含三个元素:pl,len,ti,表示这个操作进行ti次,每次将从pl+1开始的len个元素移到序列头部.分析 看到题不难想到使用平衡树将需移 ...

  7. 层次分析法(Analytic Hierarchy Process,AHP)

    昨天晚上室友问我什么是层次分析法?我当时就大概给他介绍了一下,没有细讲. 今天我仔细讲讲这个. 层次分析法是运筹学里面的一种方法,是讲与决策总是有关的元素分解成目标.准则.方案等层次,在此基础上进行定 ...

  8. html相关标记的含义

    HTML标记含义1.<html>...</html> :html 文档标记2.<head>...</head> :文档头标记3.<title> ...

  9. 《Head First Servlets & JSP》-6-会话管理-listener etc. demo

    工程结构 上下文参数示例 示例程序展示了如何从上下文读取参数,并在上下文监听器中生成属性对象和在上下文中设置属性. 建立一个简单的JavaBean对象作为属性:Dog.java package com ...

  10. Netty学习大纲

    1.BIO.NIO和AIO2.Netty 的各大组件3.Netty的线程模型4.TCP 粘包/拆包的原因及解决方法5.了解哪几种序列化协议?包括使用场景和如何去选择6.Netty的零拷贝实现7.Net ...