题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4027

Can you answer these queries?

Description

Problem 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 263.
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

线段树,区间开方求和。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define lc root<<1
#define rc root<<1|1
#define mid ((l+r)>>1)
typedef unsigned long long ull;
const int Max_N = ;
struct Node { ull val; bool flag; };
struct SegTree {
Node seg[Max_N << ];
inline void push_up(int root) {
seg[root].val = seg[lc].val + seg[rc].val;
}
inline void built(int root, int l, int r) {
seg[root].flag = false;
if (l == r) {
scanf("%lld", &seg[root].val);
return;
}
built(lc, l, mid);
built(rc, mid + , r);
push_up(root);
}
inline void update(int root, int l, int r, int x, int y) {
if (x > r || y < l || seg[root].flag) return;
if (l == r) {
seg[root].val = (ull)sqrt((double)seg[root].val);
if ( == seg[root].val) seg[root].flag = true;
return;
}
update(lc, l, mid, x, y);
update(rc, mid + , r, x, y);
push_up(root);
seg[root].flag = seg[lc].flag && seg[rc].flag;
}
inline ull query(int root, int l, int r, int x, int y) {
if (x > r || y < l) return ;
if (x <= l && y >= r) return seg[root].val;
ull v1 = query(lc, l, mid, x, y);
ull v2 = query(rc, mid + , r, x, y);
return v1 + v2;
}
}seg;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n, q, a, b, c, k = ;
while (~scanf("%d", &n)) {
seg.built(, , n);
scanf("%d", &q);
printf("Case #%d:\n", k++);
while (q--) {
scanf("%d %d %d", &a, &b, &c);
if (b > c) b ^= c ^= b ^= c;
if (!a) seg.update(, , n, b, c);
else printf("%lld\n", seg.query(, , n, b, c));
}
printf("\n");
}
return ;
}

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

  1. HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】

    Can you answer these queries? Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & ...

  2. HDU 4027 Can you answer these queries?(线段树区间开方)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  3. 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 ...

  4. HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)

    题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的 ...

  5. 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 ...

  6. hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  7. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  8. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  9. HDU - 4027 Can you answer these queries?(线段树区间修改)

    https://cn.vjudge.net/problem/HDU-4027 题意 给一个有初始值的数组,存在两种操作,T=0时将[L,R]的值求平方根,T=1时查询[L,R]的和. 分析 显然不符合 ...

随机推荐

  1. 【drp 10】JSP页面中model1和model2的区别

    一.基本概念 1.1,model1 model1的开发模式是:jsp+javabean的模式,它的核心是JSP页面,在这个页面中,jsp页面负责整合页面和javabean(业务逻辑),而且渲染页面.它 ...

  2. Oracle:使用过程中的问题集锦

    导读:在使用Oracle的过程中,又频繁的出问题.突然间就连接不上,各种报错了.在此,将问题给记录下来,方便以后查看. 一.ora 12514监听程序当前无法识别 之前一直链接使用的好好的,突然就连接 ...

  3. gson转换带有objectId的问题

    /** * * @Description: objectid 转换成string 不然就会objectid对象序列化了 * @param @param obj * @param @return * @ ...

  4. CDbConnectionExt.php 23.2实现数据库的主从分离,该类会维护多个数据库的配置:一个主数据库配置,多个从数据库的配置

      <?php   /** * 实现数据库的主从分离,该类会维护多个数据库的配置:一个主数据库配置,多个从数据库的配置. * 具体使用主数据库还是从数据库,使用如下规则: * 1.CDbComm ...

  5. 第四次java实验报告

    20145306 实验四 java 开发基础 设计过程: 1.创建项目 2.选择activity_main.xml 3.显示自己的学号 4.双击改变字体大小 5.预览

  6. angular.foreach 循环方法使用指南

    angular有自己的生命周期.循环给一个 angular监听的变量复值时.最好还是用angular自带的循环方法.“angular.foreach” },{a:}]; angular.forEach ...

  7. javaSE第二天

    第二天    7 1:关键字(掌握)    7 2:标识符(掌握)    7 (1)就是给类,接口,方法,变量等起名字的字符序列    7 (2)组成规则:    7 (3)注意事项:    8 (4 ...

  8. IOS CLLocationManager定位反编码位置信息

    //获取位置和坐标#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1        if (IOS_VERSION >= 8.0) {   ...

  9. wordpress代理设置

    打开wp-config.php,在页首加上以下语句: define('WP_PROXY_HOST', '192.168.84.101'); define('WP_PROXY_PORT', '8080' ...

  10. 分享一个jquery写的类似于百度的搜索框,(可动态配置,可单列或者table格式,可填充数据)

    需求:类似于百度的搜索框,可配置,可单列可table格式,可填充数据.页面可多次使用,简单,易用. 想法:使用jquery,css,ajax,前台调用,后台返回json数据. jquery代码: va ...