hdu 4027 2011上海赛区网络赛G 线段树 成段平方根 ***
不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root 1,n,1
#define mid ((l+r)>>1)
const int MAXN=;
int n,m,t,Min;
ll sum[MAXN<<];
int col[MAXN<<];
void pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
col[rt]=col[rt<<]&&col[rt<<|];
}
void build(int l,int r,int rt){
col[rt]=;
if(l==r)
{
scanf("%I64d",&sum[rt]);
return;
}
build(lson);
build(rson);
pushup(rt);
}
void update(int L,int R,int l,int r,int rt)
{
if(l==r)
{
sum[rt]=sqrt(sum[rt]);
if(sum[rt]==) col[rt]=;
return;
}
if(L<=mid&&!col[rt<<]) update(L,R,lson);
if(R>mid&&!col[rt<<|]) update(L,R,rson);
pushup(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(l>=L&&r<=R)
{
return sum[rt];
}
ll ans=;
if(L<=mid) ans+=query(L,R,lson);
if(R>mid) ans+=query(L,R,rson);
return ans;
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif int ca=;
while(scanf("%d",&n)!=EOF)
{
build(root);
int q;
scanf("%d",&q);
printf("Case #%d:\n",ca++);
int s,L,R;
while(q--)
{
scanf("%d%d%d",&s,&L,&R);
if(L>R) swap(L,R);
if(s==)
{
update(L,R,root);
}
else
{
ll w=query(L,R,root);
printf("%I64d\n",w);
}
}
printf("\n");
}
}
hdu 4027 2011上海赛区网络赛G 线段树 成段平方根 ***的更多相关文章
- hdu 4046 2011北京赛区网络赛G 线段树 ***
还带这么做的,卧槽,15分钟就被A了的题,居然没搞出来 若某位是1,则前两个为wb,这位就是w #include<cstdio> #include<cstring> #defi ...
- hdu 4026 2011上海赛区网络赛F TSP ****
没看过TSP,先mark //4838039 2011-10-27 23:04:15 Accepted 4026 2343MS 31044K 3143 B C++ Geners //状态压缩DP的TS ...
- hdu 4025 2011上海赛区网络赛E 压缩 ***
直接T了,居然可以这么剪枝 题解链接:点我 #include<cstdio> #include<map> #include<cstring> #define ll ...
- hdu 4023 2011上海赛区网络赛C 贪心+模拟
以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algori ...
- hdu 4028 2011上海赛区网络赛H dp+map离散
一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- hdu 4036 2011成都赛区网络赛F 模拟 **
为了确保能到达终点,我们需要满足下面两个条件 1.能够到达所有山顶 2.能够在遇到苦土豆时速度大于他 二者的速度可以用能量守恒定律做,苦土豆的坐标可通过三角形相似性来做 #include<cst ...
- hdu 4044 2011北京赛区网络赛E 树形dp ****
专题训练 #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
随机推荐
- [转]Java 征途:行者的地图
前段时间应因缘梳理了下自己的 Java 知识体系, 成文一篇望能帮到即将走进或正在 Java 世界跋涉的程序员们. 第一张,基础图 大约在 2003 年我开始知道 Java 的(当时还在用 Delph ...
- Remove Duplicate Letters I & II
Remove Duplicate Letters I Given a string which contains only lowercase letters, remove duplicate le ...
- Kinect SDK 安装失败
错误提示:Kinect Management failed to start. 原因: 1, Kinect Management 服务相依的 Plug and Play的服务没有启动. 2,系统安装了 ...
- 【转】Android Support v4、v7、v13的区别和应用场景
google提供了Android Support Library package 系列的包来保证来高版本sdk开发的向下兼容性,即我们用4.x开发时,在1.6等版本上,可以使用高版本的有些特性,如fr ...
- Solr安装过程
Solr安装过程 下载相关资料 solr 4.2.0 http://lucene.apache.org/solr/ 期间安装过 solr 4.3.0 很可惜没有配置成功 apache-tomcat-7 ...
- hdu 1972.Printer Queue 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1972 题目意思:需要模拟打印机打印.打印机里面有一些 job,每个job被赋予1-9的其中一个值,越大 ...
- Base64编码格式详解
什么是Base64? 按照RFC2045的定义,Base64被定义为:Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式.(The Base64 Content-T ...
- (2016弱校联盟十一专场10.2) E.Coins
题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...
- Collection 集合类
ArrayList: 基于动态数组的List 它有两个重要的变量,size为存储的数据的个数.elementData 数组则是arraylist 的基础,因为他的内部就是通过这个数组来存储数据的. p ...
- August 26th 2016 Week 35th Friday
It always seems impossible until it's done. 在事情未完成之前,一切都看似不可能. When I was young, once I had to lift ...