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. feign的callback设定后,项目启动错误

    错误如下: Error starting ApplicationContext. To display the auto-configuration report re-run your applic ...

  2. python对日志处理的封装

    一个适应性范围较广的日志处理 # coding=utf8 """ @author bfzs """ import os import log ...

  3. 关于解决emoji表情的存储

    近段时间处理,由于工作需求,需要使得用户插入的emoji表情能够正常显示及使用,所以做个总结,以备后用. 说明:本方法只在mysql环境中测试 1.首先程序在连接数据库时,要指定数据库字符集的设置 c ...

  4. [OpenCV] Samples 15: Background Subtraction and Gaussian mixture models

    不错的草稿.但进一步处理是必然的,也是难点所在. Extended: 固定摄像头,采用Gaussian mixture models对背景建模. OpenCV 中实现了两个版本的高斯混合背景/前景分割 ...

  5. iOS js与objective-c的交互(转)

    在写 JavaScript 的时候,可以使用一个叫做 window 的对象,像是我们想要从现在的网页跳到另外一个网页的时候,就会去修改 window.location.href 的位置:在我们的 Ob ...

  6. Java从控制台接受输入字符

    创建一个类,在该类的主方法中创建Scanner扫描起来封装System类的in输入流,然后提示用户输入身份证号码,并输入身份证号码的位数. 代码如下: import java.util.Scanner ...

  7. Linux下tomcat无法启动

    场景:干净的tomcat,刚解压 1 通过./startup.sh,提示启动成功,但查看没有日志 2 通过netstat -tln查看端口,发现找不到8080 3 通过./catalina.sh ru ...

  8. 基本select 语句总结

    --------------基本select语句总结 8.6---------------------------------------------------------------------- ...

  9. SpringMVC -- 梗概--源码--壹--跳转

    1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...

  10. python读取文件embedded null character是什么原因

    地址的\需要转义符: 将\写成\\ 或者在整个字符串前面添加字母r