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. nano-sql.js的基本操作

    nano-sql是一个小而快的数据库引擎, 他支持联合查询, 分组, 事务, ORM等功能, 支持 内存, indeedDB, Local Storage, WebSQL, Level DB 注意第一 ...

  2. Linux oracle数据库创建表空间、用户并赋予权限

    管理员用户登录oracle数据库 1.创建临时表空间 select name from v$tempfile;查出当前数据库临时表空间,主要是使用里面的存放路径: 得到其中一条记录/opt/oracl ...

  3. hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configured filemask: output.xml

    错误描述: hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configu ...

  4. U3D功能脚本备忘

    编译器属性 属性 介绍 用例 AddComponentMenu 在Component菜单中添加新的菜单项 [AddComponentMenu("Duan/Script/TestScript& ...

  5. mybatis 之 parameterType="String" resultType="java.util.HashMap">

    public ServiceMessage<Map<String, String>> getGoodsStockNo( List<Map<String, Strin ...

  6. MPAndroidChart market右边显示不全问题

    //lineChart.setMarkerView(new CustomChartMarkerView(activity, R.layout.line_chart_maker));//add mark ...

  7. python --->字典 集合 学习笔记

    1.字典--->创建空字典:dict={} broa=["李宁",”耐克“,“阿迪达斯”,“鱼c工作室”] sloga=[“A”,“B”,“C”,“D”] dict={&qu ...

  8. ubuntu MySQL采用apt-get install安装目录

    一). ubuntu下mysql安装布局: /usr/bin                      客户端程序和mysql_install_db /var/lib/mysql            ...

  9. LINUX网络之ifconfig命令与ping

    ifconfig命令 网络配置 ifconfig命令被用于配置和显示Linux内核中网络接口的网络参数.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息 ...

  10. HttpClient详细解释

    Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且 ...