Can you answer these queries? HDU - 4027(线段树+技巧)
题意:给一个数组序列, 数组长度为100000
两种操作: 一种操作是将某一个固定区间所有数开方(向下取整)
另一种操作是询问某个区间的所有数字之和。
就是在修改的时候加一个判断即可。。
还要注意 a 可能 比 b 大
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
typedef long long LL;
int a, b, x, y;
LL ans; struct node{
int l, r;
LL w, f;
}Node[maxn*+]; void build(int k, int ll, int rr)
{
Node[k].l = ll, Node[k].r = rr;
if(Node[k].l == Node[k].r)
{
scanf("%lld",&Node[k].w);
return;
}
int m = (ll + rr) / ;
build(k<<, ll, m);
build(k<<|, m+, rr);
Node[k].w = Node[k*].w + Node[k*+].w;
} void chp(int k)
{
if(Node[k].l == Node[k].r)
{
Node[k].w = floor(sqrt((double)Node[k].w));
return;
}
if(Node[k].l >= a && Node[k].r <= b && Node[k].r - Node[k].l + == Node[k].w){
return;
}
// if(Node[k].f) down(k);
int m = (Node[k].l + Node[k].r) / ;
if(a <= m) chp(k<<);
if(b > m) chp(k<<|);
Node[k].w = Node[k<<].w + Node[k<<|].w;
} void qinter(int k)
{
if(Node[k].l >= a && b >= Node[k].r)
{
ans += Node[k].w;
return;
}
int m = (Node[k].l + Node[k].r) / ;
if(a <= m) qinter(k*);
if(b > m) qinter(k*+);
} int main()
{
int n, m, kase = ;
while(~scanf("%d",&n))
{
ans = ;
mem(Node, );
build(, , n);
scanf("%d",&m);
printf("Case #%d:\n",++kase);
for(int i=; i<m; i++)
{
int temp;
scanf("%d",&temp);
if(temp == )
{
scanf("%d%d",&a,&b);
if(a > b) swap(a, b);
chp();
}
else if(temp == )
{
ans = ;
scanf("%d%d",&a, &b);
if(a > b) swap(a, b);
qinter();
printf("%lld\n",ans);
}
}
printf("\n");
}
return ;
}
Can you answer these queries? HDU - 4027(线段树+技巧)的更多相关文章
- Can you answer these queries? HDU 4027 线段树
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...
- V - Can you answer these queries? HDU - 4027 线段树 暴力
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
- Can you answer these queries? HDU - 4027 (线段树,区间开平方,区间求和)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- spoj gss2 : Can you answer these queries II 离线&&线段树
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)
GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...
- Can you answer these queries III(线段树)
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...
- hdu4027Can you answer these queries?【线段树】
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- 2018.10.16 spoj Can you answer these queries V(线段树)
传送门 线段树经典题. 就是让你求左端点在[l1,r1][l1,r1][l1,r1]之间,右端点在[l2,r2][l2,r2][l2,r2]之间且满足l1≤l2,r1≤r2l1\le l2,r1 \l ...
- GSS1 - Can you answer these queries I(线段树)
前言 线段树菜鸡报告,stO ZCDHJ Orz,GSS基本上都切完了. Solution 考虑一下用线段树维护一段区间左边连续的Max,右边的连续Max,中间的连续Max还有总和,发现这些东西可以相 ...
随机推荐
- GPXReader工具代码简析
完整的文件在TerraExplorer Pro的默认安装目录下C:\Program Files (x86)\Skyline\TerraExplorer Pro\Tools\GPXReader: 如果你 ...
- RocketMQ环境搭建
1 源码下载 wget http://mirror.bit.edu.cn/apache/rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip unzip ...
- 在angularjs实现一个时钟
想在网页上,显示当前系统时钟. <body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind ...
- 同一个解决方案或有依赖关系的两个项目引用同名但不同版本的DLL
问题描述 我们最近在使用Redis作Session的集中化,中间碰到了一个如下问题:我们有一些项目比较老,引用了NewtonJson的4.0.3.0版本的DLL,但是Redis提供的C#集成DLL引用 ...
- 【php增删改查实例】第十二节 - 数据删除功能
1.单条数据删除 思路:首先,需要也只能允许用户勾选一条数据,然后弹出一个确认框,问用户是否真的要删除?如果是,就把ID传递到PHP,然后写一个delete语句,通过ID去删除即可. 画好了按钮之后, ...
- Flask系列学习
一.Flask系列学习(基础) Flask学习-前言 Flask学习-Flask基础之WSGI Flask学习-Flask app启动过程 Flask学习-Flask app接受第一个HTTP请求 F ...
- LESS SCSS 预编译语言
前 言 JRedu LESS 是一门 CSS 预处理语言,它扩展了 CSS 语言,增加了变量.Mixin.函数等特性,使 CSS 更易维护和扩展. LESS 为 Web 开发者带来了福音,它在 ...
- C语言----数据类型(基础篇一)
C语言的入门程序模板 #include <stdio.h> /*使用或者包含系统里面的程序*/ main() /*程序入口点*/ { /*起点*/ +; /*叫计算机执行的指令*/ } / ...
- Apache之Rewrite和RewriteRule规则梳理以及http强转https的配置总结
一. 简单实例介绍一般来说,apache配置好http和https后,如果想要做http强转到https,需要设置url重定向规则,大致需要下面几个步骤即可完成配置: 1)在httpd.conf文件里 ...
- db2安装
官网下载: DB2 11.1 data server trial for Linux® on AMD64 and Intel® EM64T systems (x64)v11.1_linuxx64_se ...