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.

Input

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

Output

For 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

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

Sample Output

Case #1:
19
7
6

因为更新的时候是进行开方 所以常规的更新就不行了

但是因为是开方 对64位的数来说 开方的次数是有限制的

而且当一个数开方成都是1以后再开方也还是1 所以一个区间都是1的时候就不需要继续更新了

刚开始query用的是之前的写法 结果T了

看题解改成了这样就过了


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define inf 1e18
using namespace std; int m, n;
const int maxn = 100005;
int weapon[maxn];
long long tree[maxn << 2], lazy[maxn<<2]; void pushup(int rt)//更新
{
tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
} void build(int l, int r, int rt)
{
if(l == r){
scanf("%lld", &tree[rt]);
return;
}
int m = (l + r) >> 1;
build(l, m, rt << 1);
build(m + 1, r, rt << 1 | 1);
pushup(rt);
} /*void update(int L, int C, int l, int r, int rt)
{
if(l == r){
tree[rt] += C;
return;
}
int m = (l + r) >>1;
if(L <= m) update(L, C, l, m, rt << 1);
else update(L, C, m + 1, r, rt << 1 | 1);
pushup(rt);
}*/ void update(int L, int R, int l, int r, int rt)
{
if(tree[rt] == r - l + 1){//已经全部是1了就不用更新了
return;
}
if(l == r){
tree[rt] = sqrt(tree[rt]);
return;
}
int m = (l + r) >> 1;
if(L <= m) update(L, R, l, m, rt << 1);
if(R > m) update(L, R, m + 1, r, rt << 1 | 1);
pushup(rt);
} long long query(int L, int R, int l, int r, int rt)
{
if(l == L && r == R){
return tree[rt];
}
int m = (l + r) >> 1;
//pushdown(rt, m - l + 1, r - m); long long ans = 0;
if(R <= m) return query(L, R, l, m, rt << 1);
if(L > m) return query(L, R, m + 1, r, rt << 1 | 1);
return query(L, m, l, m, rt << 1) + query(m + 1, R, m + 1, r, rt<<1|1);
} int main()
{
int cas = 1;
while(scanf("%d", &n) != EOF){
build(1, n, 1);
scanf("%d", &m);
printf("Case #%d:\n", cas++);
while(m--){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if(b > c){
swap(b, c);
}
if(a == 0){
update(b, c, 1, n, 1);
}
else{
printf("%lld\n", query(b, c, 1, n, 1));
}
}
printf("\n");
}
return 0;
}

hdu4027Can you answer these queries?【线段树】的更多相关文章

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

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

  2. hdu4027Can you answer these queries?(线段树)

    链接 算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记.查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新. 注意用——int64 注意L会大于R 这点我很纠结..您出题人故意 ...

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

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

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

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

  6. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  7. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

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

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

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

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

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

随机推荐

  1. 使用editorconfig配置你的编辑器

    摘要: 在团队开发中,统一的代码格式是必要的.但是不同开发人员使用的编辑工具可能不同,这样就造成代码的differ.今天给大家分享一个很好的方法来使不同的编辑器保持一样的风格. 不同的编辑器也有设置代 ...

  2. 解决 iOS7 通过tag 找不到 UITableViewCell 的子控件(转)

    转自:http://www.cnblogs.com/waiwaibuzhidao/p/3340400.html 当iOS7问世,程序的世界就混乱了,以前良好的程序,现在是一塌糊涂,于是只能把问题一个一 ...

  3. SpringMVC由浅入深day02_9RESTful支持

    9 RESTful支持 9.1 什么是RESTful RESTful架构,就是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以正得到越来越多网站的采用. RESTful( ...

  4. WPF导航总结

    使用导航的目的是从一个页面进入到另一个页面.无论是预先决定的线性顺序(向导)还是基于层次的用户驱动程序(大部分网站的形式),或者动态生成的路径,主要有3种方法实现:调用Navigate方法,使用Hyp ...

  5. 在 Linux 使用 GCC 编译C语言共享库

    对任何程序员来说库都是必不可少的.所谓的库是指已经编译好的供你使用的代码.它们常常提供一些通用功能,例如链表和二叉树可以用来保存任何数据,或者是一个特定的功能例如一个数据库服务器的接口,就像MySQL ...

  6. flask livereload用法

    #coding=utf-8 from flask import Flask from flask_script import Manager app = Flask(__name__) manager ...

  7. java接口定义的静态方法和默认如何在类实现的时候使用

    在 JDK1.8,允许我们给接口添加两种非抽象的方法实现: 1.默认方法,添加 default 修饰即可: 2.静态方法,使用 static 修饰:示例如下: 这样可以实现接口的增强,那我们在类实现接 ...

  8. Ubuntu12.04 15.04禁止移动介质自动播放

    网上有有很多关于Ubuntu10.04关闭移动介质自动播放的方法,包括在文件管理器里面设置或者使用gconf-editor,但是从12.04开始这两种方法都不再好用了,关于移动介质的处理方法被移到了S ...

  9. Android 验证APK是否已经签名或是否是Debug签名

    https://source.android.google.cn/ http://www.android-doc.com/tools/publishing/app-signing.html Signi ...

  10. Telnet是什么意思又是什么协议 Telnet有什么作用及功能

    Telnet是teletype network的缩写,专业的说,Telnet是Internet上远程登录的一种程序:它可以让您的电脑通过网络登录到网络另一端的电脑上,甚至还可以存取那台电脑上的文件. ...