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. 【框架学习与探究之定时器--Quartz.Net 】

    声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7572174.html 前言 这里相信大部分玩家之前现在都应该有过使用定时器的时候或者需求,例如什么定时 ...

  2. escape()、encodeURI()、encodeURIComponent()区别详解(转)

      JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,dec ...

  3. iOS根据域名获取ip地址

    引入头文件 #include <netdb.h> #include <sys/socket.h> #include <arpa/inet.h> //根据域名获取ip ...

  4. uvalive 3029 City Game

    https://vjudge.net/problem/UVALive-3029 题意: 给出一个只含有F和R字母的矩阵,求出全部为F的面积最大的矩阵并且输出它的面积乘以3. 思路: 求面积最大的子矩阵 ...

  5. 关于xamarin.forms 中 list 的loadmore

    前言 最近几天在研究上拉加载啊,下拉刷新啊什么的.然而坑爹的事情总是那么多.在xamarin.forms中,list自带的,并没有上拉加载的这个属性(难道当初他们封装方法时,就不会想到数据多了会咋整吗 ...

  6. Ghost文件封装说明

    一.先列举目前Windows系统安装方式: 1.光盘安装 1.1 使用可刻录光驱将系统ISO文件刻录至DVD光盘,刻录工具比较多,QA目前使用Ultra ISO. 1.2 安装电脑从DVD光盘启动,无 ...

  7. Jquery购物车jsorder改进版,支持后台处理程序直接转换成DataTable处理

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. redis的发布订阅模式pubsub

    前言 redis支持发布订阅模式,在这个实现中,发送者(发送信息的客户端)不是将信息直接发送给特定的接收者(接收信息的客户端),而是将信息发送给频道(channel),然后由频道将信息转发给所有对这个 ...

  9. Linux基础命令讲解(二)

    Linux命令基本格式: 命令 [参数] [路径文件] 方括号内容可省略 查看命令帮助手段: 1 man 命令名 (man 还可以获取配置文件,函数的帮助) 2 命令 --help 3 help 命令 ...

  10. Cygwin-添加到右键菜单脚本--一键安装、卸载

    平时习惯用一些linux命令来完成工作,在Windows上有cygwin和gitbash两个选择.这两个我都装了. 相对来说cygwin支持的功能更多一些,但是它没有默认绑定到右键菜单.为此,我想到用 ...