Can you answer these queries?

Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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
/*
题意:有 n艘战舰,每艘战舰都有一定的能量值,炮弹每次炮轰区间内的战舰,区间内战舰的能量值变为原来的想下取整的开方数,
然后查询区间内的战舰总能量 初步思路:addv数组用来储存这棵树上的节点被轰过几次,向上向下更新的时候不会写了,试一下笨办法单点更新更新函数,不能找
到满足的区间就更新,必须要跟新到叶子节点才能,addv数组现在的作用是记录 #错误:把case i漏掉了
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/******************************线段树区间更新模板*************************************/
const int MAXN=+;
#define lson i*2,l,m
#define rson i*2+1,m+1,r
ll sum[MAXN<<];
ll addv[MAXN<<]; void PushUp(int i)
{
sum[i]=sum[i*]+sum[i*+];
addv[i]=addv[i*]&&addv[i*+];
} void build(int i,int l,int r)
{
addv[i]=;
if(l==r)
{
scanf("%lld",&sum[i]);
return ;
}
int m=(l+r)>>;
build(lson);
build(rson);
PushUp(i);
} void update(int ql,int qr,int i,int l,int r)
{
if(l==r)//必须更新到叶子节点
{
sum[i]= sqrt(sum[i]);
if(sum[i]<=) addv[i]=;
return ;
}
int m=(l+r)>>;
if(ql<=m&&!addv[i*]) update(ql,qr,lson);
if(m<qr&&!addv[i*+]) update(ql,qr,rson);
PushUp(i);
} ll query(int ql,int qr,int i,int l,int r)
{
if(ql<=l&&r<=qr)
{
return sum[i];
}
int m=(l+r)>>;
ll res=;
if(ql<=m) res+=query(ql,qr,lson);
if(m<qr) res+=query(ql,qr,rson);
return res;
}
/******************************线段树区间更新模板*************************************/
void init(){
memset(sum,,sizeof sum);
memset(addv,,sizeof addv);
}
int n,q;
int str,x,y;
int Case=;
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF){
printf("Case #%d:\n",Case++);
init();
build(,,n);
scanf("%d",&q);
for(int i=;i<q;i++){
scanf("%d%d%d",&str,&x,&y);
if(x>y) swap(x,y);
if(str){
printf("%lld\n",query(x,y,,,n));
}else{
update(x,y,,,n);
}
}
printf("\n");
}
return ;
}

Can you answer these queries?的更多相关文章

  1. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  2. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

  3. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  4. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

  5. GSS6 4487. Can you answer these queries VI splay

    GSS6 Can you answer these queries VI 给出一个数列,有以下四种操作: I x y: 在位置x插入y.D x  : 删除位置x上的元素.R x y: 把位置x用y取替 ...

  6. GSS5 spoj 2916. Can you answer these queries V 线段树

    gss5 Can you answer these queries V 给出数列a1...an,询问时给出: Query(x1,y1,x2,y2) = Max { A[i]+A[i+1]+...+A[ ...

  7. GSS3 SPOJ 1716. Can you answer these queries III gss1的变形

    gss2调了一下午,至今还在wa... 我的做法是:对于询问按右区间排序,利用splay记录最右的位置.对于重复出现的,在splay中删掉之前出现的位置所在的节点,然后在splay中插入新的节点.对于 ...

  8. GSS1 spoj 1043 Can you answer these queries I 最大子段和

    今天下午不知道要做什么,那就把gss系列的线段树刷一下吧. Can you answer these queries I 题目:给出一个数列,询问区间[l,r]的最大子段和 分析: 线段树简单区间操作 ...

  9. BZOJ2482: [Spoj1557] Can you answer these queries II

    题解: 从没见过这么XXX的线段树啊... T_T 我们考虑离线做,按1-n一个一个插入,并且维护区间[ j,i](i为当前插入的数)j<i的最优值. 但这个最优值!!! 我们要保存历史的最优值 ...

  10. SPOJ 1557. Can you answer these queries II 线段树

    Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/pr ...

随机推荐

  1. C++初学 virtual 相关

    声明: 1.为了节省篇幅,头文件和域什么的都没写.另外可能是java转C++,有些叫法可能会不对 2.因初学,都是自己摸索的,有错望指出,勿喷 假设父类声明 Parent.h中如下 class Par ...

  2. nodejs 初次链接 mongodb 的详细细节

    时间  2016-06-2613:05:16 在前端的学习也有一段时间了,学习了html,css,javascript,jqery,ajax,php,mysql,学习了这些,了解了一些皮毛,也没有什么 ...

  3. 走进Node.js 之 HTTP实现分析

    作者:正龙(沪江Web前端开发工程师) 本文为原创文章,转载请注明作者及出处 上文"走进Node.js启动过程"中我们算是成功入门了.既然Node.js的强项是处理网络请求,那我们 ...

  4. 关于DbContext能不能单次请求内唯一?DbContex需不需要主动释放?欢迎各路大侠来“参战”!

    基于前篇文章<HiBlogs>重写笔记[1]--从DbContext到依赖注入再到自动注入园友@Flaming丶淡蓝@ 吴瑞祥 提出了讨论和质疑,吓得我连夜查询资料(玩笑~). 本来文章的 ...

  5. php字符的替换,截取,指定查找

    <?php/** * Created by 郭鹏. * User: msi * Date: 2017/9/27 * Time: 14:17 *///随机数生成器echo rand();echo ...

  6. Instance of 的用法

    来自:百度百科 instanceof主要用于判断是否是某个类的实例 任何的对象都可以调用 返回结果是Boolean型数值Class AA a=new A();boolean b=a instanceo ...

  7. Select()使用否?

    David Treadwell ,Windows Socket 的一位开发者,曾经在他的一篇名为"Developing Transport-Independent Applications ...

  8. hdu 4778 Gems Fight! 状态压缩DP

    Gems Fight! Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)T ...

  9. 基于nginx的虚拟主机的配置

    安装pcre tar -xvf pcre-8.32.tar.gz cd pcre-8.32 ./configure make;make install 安装nginx 首先创建一个nginx用户,以n ...

  10. HDU5661 Claris and XOR

    我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...