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取替 ...
随机推荐
- iOS开发-Swift获取手机设备信息(UIDevice)
使用UiDevice获取设备信息 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice. ...
- Linux-进程内存占用情况
可以直接使用top命令后,查看%MEM的内容.可以选择按进程查看或者按用户查看,如想查看oracle用户的进程内存使用情况的话可以使用如下的命令: (1)top top命令是Linux下常用的性能分析 ...
- MongoDB笔记(二):MongoDB下Shell的基本操作
一.mongoDB与关系型数据库对比 对比项 mongoDB 关系型数据库(oracle.mysql) 表 集合List 二维表table 表的一行数 ...
- 带圈圈的数字1~50,求50以上,不要word的
①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿
- 预装WIN8改装WIN7之BIOS设置
不少预装WIN8/10的朋友觉得WIN8/10不好用,想改装WIN7,可改装之后常常出现各种问题,甚至不能启动,往往是BIOS设置不当. 本文以联想小新V2000 预装WIN8.1中文版为例,说说WI ...
- android应用多线程守护让你非常难杀死它
1.android 应用开启后启动一个服务 public class TestserviceActivity extends Activity { /** Called when the activi ...
- GoogLeNet模型的微调
我从零开始训练了GoogLeNet模型. 但它没有给我带来希望的结果. 作为替代,我想对我的数据集中的GoogLeNet模型进行微调. 有谁知道我应该遵循什么步骤? 采纳答案: 假设你正在尝试做图像分 ...
- 【转载】浏览器加载和渲染html的顺序
1.浏览器加载和渲染html的顺序 1.IE下载的顺序是从上到下,渲染的顺序也是从上到下,下载和渲染是同时进行的.2.在渲染到页面的某一部分时,其上面的所有部分都已经下载完成(并不是说所有相关联的元素 ...
- hdu 4059 数论+高次方求和+容斥原理
http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...
- pthread linux mutet:example1
#include<iostream> #include<unistd.h> #include<pthread.h> #include<string> u ...