hdu4027Can you answer these queries?(线段树)
算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记。查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新。
注意用——int64
注意L会大于R 这点我很纠结。。您出题人故意的吗 WAn次。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100010
#define LL __int64
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL s[N<<],f[N<<];
LL a[N];
void up(int w)
{
s[w] =s[w<<]+s[w<<|];
f[w] = (f[w<<]&&f[w<<|]);
}
void build(int l,int r,int w)
{
if(l==r)
{
s[w] = a[l];
if(a[l]==||a[l]==) f[w] = ;
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w);
}
void update(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
if(l==r)
{
LL k = sqrt(s[w]*1.0);
if(k*k>s[w])
k--;
s[w] = k;
if(s[w]<=)
f[w] = ;
// up(w);
return ;
}
if(f[w])
{
up(w);
return ;
}
else
{
int m = (l+r)>>;
if(a<=m)
update(a,b,l,m,w<<);
if(b>m)
update(a,b,m+,r,w<<|);
up(w);
return ;
}
}
int m = (l+r)>>;
if(a<=m)
update(a,b,l,m,w<<);
if(b>m)
update(a,b,m+,r,w<<|);
up(w);
}
LL query(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
int m = (l+r)>>;
LL res = ;
if(a<=m) res+=query(a,b,l,m,w<<);
if(b>m) res+=query(a,b,m+,r,w<<|);
return res;
}
int main()
{
int i,n,q;
int k,x,y,kk=;
while(scanf("%d",&n)!=EOF)
{
memset(f,,sizeof(f));
for(i = ; i <=n ;i++)
{
scanf("%I64d",&a[i]);
}
build(,n,);
scanf("%d",&q);
printf("Case #%d:\n",++kk);
while(q--)
{
scanf("%d%d%d",&k,&x,&y);
if(x>y) swap(x,y);
if(k)
{
printf("%I64d\n",query(x,y,,n,));
}
else
{
update(x,y,,n,);
}
}
puts("");
}
return ;
}
hdu4027Can you answer these queries?(线段树)的更多相关文章
- HDU-4027-Can you answer these queries?线段树+区间根号+剪枝
传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...
- 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 ...
- 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 ...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- hdu 4027 Can you answer these queries? 线段树
线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...
- HDU4027 Can you answer these queries? 线段树
思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...
- 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 ...
- HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)
题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...
随机推荐
- C#评分小系统练习
一个经理类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...
- codeforces 665B B. Shopping(水题)
题目链接: B. Shopping time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Python:元组
元组:只读,不能修改,使用小括号 创建元组: tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5 ) tup3 = &q ...
- apache web 服务器
0. 特性与特点 性能方面,apache 在设计时采用了以"进程"为基础的结构,自然进程比线程消耗了更多的系统开销,导致了 apache 在多处理器环境中性能有所下降: 因此,在对 ...
- Java笔记(四)
13. 集合框架: 集合中存储的都是对象的引用(地址) 迭代器:集合的取出元素的方式 import java.util.ArrayList; import java.util.Iterator; pu ...
- MongoDB 3.2复制集单节点部署(四)
MongoDB在单节点中也可以做复制集,但是仅限于测试实验,最大的好处就是部署方便快速,可以随便添加新节点,节省资源.在这里我使用的是MongoDB 3.2版本进行复制集实验(但MongoDB配置文件 ...
- bzoj 4559 [JLoi2016]成绩比较 —— DP+拉格朗日插值
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4559 看了看拉格朗日插值:http://www.cnblogs.com/ECJTUACM-8 ...
- POJ1163(基础线性DP)
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42547 Accepted: 25721 De ...
- AndroidStudio删除项目
右键左上角的 项目名 右键 > delete 磁盘里的文件还需要手动删除
- Redis简介,安装和配置,停止,卸载(图解方式)
Redis是一个Key-value的数据结构存储系统,可以已数据库的形式,缓存系统,消息处理器使用,它支持的存储类型很多,例如,String(字符串),list(列表),set(集合),zset(有序 ...