HDU4027(Can you answer these queries?)
题目链接:传送门
题目大意:有一个长度为n的数组,有m次操作,每次操作输入 v x y,v==0时x~y区间内的数都开平方并且向下取整,v==1时求x~y区间内所有数的和。
题目思路:long long范围内的数开平方不超过7次就会变成1,所以我们更新的时候只需看x~y区间内的和是不是等于区间的长度(区间内所有数都为1),是的话
不用更新了直接return,否则继续向下更新,这道题坑就坑在x,y大小不确定,需要自己判断处理(QAQ),这里TLE半天
这道题给我更大的收获是线段树不需要用struct,直接用数组模拟就行,方便高效,新技能get。ICPC,fighting!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
#define Min(x,y) (x<y?x:y)
#define Max(x,y) (x>y?x:y)
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 100000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 10001000
typedef long long LL;
typedef pair<int,int> PII; LL node[N<<];
int x,y; void build(int root,int l,int r){
if(l==r){
scanf("%lld",&node[root]);
return;
}
int mid=l+r>>;
build(lson);
build(rson);
node[root]=node[root<<]+node[root<<|];
} void add(int root,int l,int r){
if(x<=l&&r<=y&&node[root]==r-l+) return;
if(l==r){node[root]=sqrt(node[root]);return;}
int mid=l+r>>;
if(y<=mid) add(lson);
else if(x>mid) add(rson);
else{
add(lson);
add(rson);
}
node[root]=node[root<<]+node[root<<|];
} LL query(int root,int l,int r){
if(x<=l&&r<=y) return node[root];
int mid=l+r>>;
if(y<=mid) return query(lson);
else if(x>mid) return query(rson);
else return query(lson)+query(rson);
} int main(){
int n,m,i,j,v,group,Case=;
LL ans;
while(~scanf("%d",&group)){
printf("Case #%d:\n",++Case);
build(,,group);
scanf("%d",&m);
for(i=;i<m;++i){
scanf("%d%d%d",&v,&x,&y);
if(x>y) x^=y^=x^=y;
if(!v) add(,,group);
else printf("%lld\n",query(,,group));
}
printf("\n");
}
return ;
}
HDU4027(Can you answer these queries?)的更多相关文章
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- 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 ...
- kuangbin专题七 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 ...
- HDU4027 Can you answer these queries? 线段树
思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...
- 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 ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- GSS4 2713. Can you answer these queries IV 线段树
GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...
- GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树
GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...
- 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取替 ...
随机推荐
- CentOS 5 全功能WWW服务器搭建全教程 V3.0
http://hx100.blog.51cto.com/44326/339949/ 一.基本系统安装1.下载CentOS 5我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多.大家可 ...
- LoadRunner测试WebService的3种方式
LR在WebService虚拟用户协议中支持两种方式测试WebService,一种是通过“Add Service Call”的方式,一种是Import SOAP的方式. Import SOAP的方式需 ...
- hdu1236 排名(结构体排序)
排名 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- 【Java】Java_10 常量与变量
1.变量(variable) 1.1 我们通过变量来操纵存储空间中的数据,变量就是指代这个存储空间!空间位置是确定的,但是里面放置什么值不确定! 1.2 Java是一种强类型语言,每个变量都必须声明其 ...
- 字符串算法之 AC自己主动机
近期一直在学习字符串之类的算法,感觉BF算法,尽管非常easy理解,可是easy超时,全部就想学习其它的一些字符串算法来提高一下,近期学习了一下AC自己主动机.尽管感觉有所收获,可是还是有些朦胧的感觉 ...
- vue 父组件如何调用子组件的函数Methods
答案就是使用ref即可. <countdown ref="countdown"></countdown> beforeDestroy () { // 切换页 ...
- PILE读书笔记_基础知识
程序的构成 Linux下二进制可执行程序的格式一般为ELF格式. 我们可以用readelf命令来读取二进制的信息. ELF文件的主要内容就是由各个section及symbol表组成的. 下面来分别介绍 ...
- CentOS 7 安装以及配置桌面环境
一.安装 GNOME 桌面 1.安装命令: yum groupinstall "GNOME Desktop" "X Window System" " ...
- Python tkinter 用键盘移动没反映修改代码
from tkinter import * def movetriangle(event): if event.keysym == 'Up': canvas.move(a1 ...
- uva753 A Plug for UNIX 网络流最大流
C - A Plug for UNIX You are in charge of setting up the press room for the inaugural meeting of t ...