题目链接:传送门

题目大意:有一个长度为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?)的更多相关文章

  1. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

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

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

  4. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

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

  6. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

  7. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  8. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

  9. 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取替 ...

随机推荐

  1. EXTJS4自学手册——组合图像

    Ext.create('Ext.panel.Panel', { title: '组合图像', renderTo: 'ComplexDiagram', items: [{ xtype: 'button' ...

  2. 【转】SQL SERVER获取索引脚本

    关于如何获取索引脚本的语句很多,上次在项目中需要去查询并获取索引脚本,所以写了一个简单的查询语句来进行获取. WITH    idxcol          AS ( SELECT           ...

  3. win10 环境下 MinGW-w64安装

    MinGW-w64 就是 著名C/C++编译器GCC的Windows版本. 一.什么是 MinGW-w64 ?MinGW 的全称是:Minimalist GNU on Windows .它实际上是将经 ...

  4. chrome 一进入调试页面就会自己主动打断点

    近期在用chrome调试页面时.一刷新页面总会自己主动打断点.自己鼓捣了一下,发现 把它改为这个样子的时候就能够解决问题,即把调试面板上的第5个button从Deactivate breakpoint ...

  5. ISA2006安装和部署基础(虚拟机非域环境)

    0x00. 为了測试基于HTTP隧道的绕过ISA,必须搭建模拟环境,为了不麻烦,我们这里不配合域环境认证.本次实验利用Vmware 10.0搭建好开发环境,实现ISA2006安装和部署,同一时候设定基 ...

  6. sendmail发件人邮箱设定命令

    sendmail发件人邮箱设定命令   以前就碰到过设置发件人后缀的方式,这次迁移服务器居然忘记,从头开始记录下 1:第一种方法,修改/etc/hosts,据说sendmail使用hosts里面的本地 ...

  7. 一、Core Animation简介

    一.Core Animation简介 * Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代 ...

  8. python c example2:pylame2

    #include <Python.h> #include <lame.h> //pyton object variables typedef struct{ PyObject_ ...

  9. 用@spy模拟真实对象的部分行为

    1.说明在某些情况下,我们需要使用一个真实对象.但是,我们同时需要自定义该对象的部分行 为,此时用@spy 就可以帮我们达到这个目的. 2.用法: categoryService = PowerMoc ...

  10. 基于windows的resin配置

    Resin 与 Eclipse for JavaEE 的整合方法: 1.新建一个项目,将web application配置到resin.conf中 附上resin_struts2-111.conf文件 ...