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. C# IsBackground作用

    https://blog.csdn.net/snakorse/article/details/43888847 要点: 1.当在主线程中创建了一个线程,那么该线程的IsBackground默认是设置为 ...

  2. Eclipse------使用Debug As时报错java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar file:/XXX

    报错信息: java.lang.IllegalStateException: Failed to read Class-Path attribute from manifest of jar file ...

  3. html5页面平滑切换实现以及问题(20160120更新)

    注:本文是基于手机端 Hybrid APP 讨论,而不是普通的PC端网页 >> 之前的页面跳转方式: 比如有这两个页面:A.html  B.html,  A B 是纯HTML实现,没有采用 ...

  4. 接口测试之JMeter初探

    1.JMeter安装配置 )登录 http://jmeter.apache.org/download_jmeter.cgi ,下载与自己的平台相对应文件: )安装JDK(.6以上),配置环境变量JAV ...

  5. [C] 如何使用头文件 .h 编译 C 源码

    在 C 语言中,头文件或包含文件通常是一个源代码文件,程序员使用编译器指令将头文件包含进其他源文件的开始(或头部),由编译器在处理另一个源文件时自动包含进来. 一个头文件一般包含类.子程序.变量和其他 ...

  6. C++ template —— trait与policy类(七)

    第15章 trait与policy类---------------------------------------------------------------------------------- ...

  7. iOS AOP编程思想及实践

    什么是 AOP Wikipedia 上的 AOP 定义: In computing, aspect-oriented programming (AOP) is a programming paradi ...

  8. 原:android4.2.2蓝牙源码阅读--bluedroid部分

    概念: GKI:统一内核接口 BTE栈: BTU栈:BTU栈开始前必须调用BTE栈初始化 代码阅读: /external/bluetooth/bluedroid/hci/:HCI library实现 ...

  9. php的session问题总结

    1. 看文档发现,在session的configure option中有三个关于gc的,分别是: session.gc_probability "1" PHP_INI_ALL se ...

  10. IOS设计模式第二篇之单例设计模式

    现在我们的组件已经有组织了.你需要从其他的地方得到数据,你也可以创建一个API类管理数据这个下个设计模式单例里面介绍. 这个单例设计模式确保这个类仅仅拥有一个实例,并且为这个实例提供一个全局的访问点. ...