Rikka with Sequence

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2777    Accepted Submission(s): 503

Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Yuta has an array A with n numbers. Then he makes m operations on it.

There are three type of operations:

1 l r x : For each i in [l,r], change A[i] to A[i]+x
2 l r : For each i in [l,r], change A[i] to ⌊A−−√[i]⌋
3 l r : Yuta wants Rikka to sum up A[i] for all i in [l,r]

It is too difficult for Rikka. Can you help her?

 
Input
The first line contains a number t(1<=t<=100), the number of the testcases. And there are no more than 5 testcases with n>1000.

For each testcase, the first line contains two numbers n,m(1<=n,m<=100000). The second line contains n numbers A[1]~A[n]. Then m lines follow, each line describe an operation.

It is guaranteed that 1<=A[i],x<=100000.

 
Output
For each operation of type 3, print a lines contains one number -- the answer of the query.
 
Sample Input
1
5 5
1 2 3 4 5
1 3 5 2
2 1 4
3 2 4
2 3 5
3 1 5
 
Sample Output
5
6
 
Author
学军中学

【分析】这个题唯一的难点就是开根号,有两个地方没有想到,想到了就会写了。首先,对于一个数,开根号可以转化成减号,详细肩带吗。其次,对于一个区间,如果最大值==最小值,那么所有的值开完根号都相等了,还有种就就是最大值-最小值==1的时候,可能存在开完根号后差值还是一,这个时候需要特判。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int BufferSize=<<;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=,f=;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-;
for(;isdigit(c);c=Getchar()) x=x*+c-'';
return x*f;
}
const int N=1e5+;
ll sum[N<<],lz[N<<],mx[N<<],mn[N<<];
void pushUp(int rt){
sum[rt]=sum[rt<<]+sum[rt<<|];
mx[rt]=max(mx[rt<<],mx[rt<<|]);
mn[rt]=min(mn[rt<<],mn[rt<<|]);
}
void build(int rt,int l,int r){
lz[rt]=;
if(l==r){sum[rt]=read();mn[rt]=mx[rt]=sum[rt];return;}
int mid=l+r>>;
build(rt<<,l,mid);build(rt<<|,mid+,r);
pushUp(rt);
}
void pushDown(int rt,int l,int r){
if(lz[rt]!=){
int mid=l+r>>;
lz[rt<<]+=lz[rt];
lz[rt<<|]+=lz[rt];
mn[rt<<]+=lz[rt];
mx[rt<<]+=lz[rt];
mx[rt<<|]+=lz[rt];
mn[rt<<|]+=lz[rt];
sum[rt<<]+=lz[rt]*(mid-l+);
sum[rt<<|]+=lz[rt]*(r-mid);
lz[rt]=;
}
}
int x,y,t,T,n,m;
void sqrtUpdate(int rt,int l,int r){
if(x<=l&&r<=y){
if(mx[rt]==mn[rt]){
lz[rt]-=mx[rt];
mx[rt]=sqrt(mx[rt]);
mn[rt]=mx[rt];
lz[rt]+=mx[rt];
sum[rt]=mx[rt]*(r-l+);
return;
}
else if(mx[rt]==mn[rt]+){
ll x1=sqrt(mx[rt]);
ll x2=sqrt(mn[rt]);
if(x1==x2+){
lz[rt]-=(mx[rt]-x1);
sum[rt]-=(mx[rt]-x1)*(r-l+);
mx[rt]=x1;mn[rt]=x2;
return;
}
}
}
int mid=l+r>>;
pushDown(rt,l,r);
if(x<=mid)sqrtUpdate(rt<<,l,mid);
if(y>mid)sqrtUpdate(rt<<|,mid+,r);
pushUp(rt);
}
void addUpdate(int rt,int l,int r){
if(x<=l&&r<=y){
lz[rt]+=t;
sum[rt]+=1ll*(r-l+)*t;
mx[rt]+=t;mn[rt]+=t;
return ;
}
int mid=l+r>>;
pushDown(rt,l,r);
if(x<=mid)addUpdate(rt<<,l,mid);
if(y>mid)addUpdate(rt<<|,mid+,r);
pushUp(rt);
}
ll query(int rt,int l,int r){
if(x<=l&&r<=y)return sum[rt];
int mid=l+r>>;
pushDown(rt,l,r);
ll ret=;
if(x<=mid)ret+=query(rt<<,l,mid);
if(y>mid)ret+=query(rt<<|,mid+,r);
return ret;
}
int main(){
T=read();
while(T--){
n=read();m=read();
build(,,n);
while(m--){
int op;
op=read();x=read();y=read();
if(op==){
t=read();addUpdate(,,n);
}
else if(op==)sqrtUpdate(,,n);
else printf("%I64d\n",query(,,n));
}
}
return ;
}

HDU 5828 Rikka with Sequence(线段树 开根号)的更多相关文章

  1. hdu 5828 Rikka with Sequence 线段树

    Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...

  2. HDU 5828 Rikka with Sequence(线段树区间加开根求和)

    Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he g ...

  3. HDU 5828 Rikka with Sequence (线段树+剪枝优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,三种操作.操作1是将l到r之间的数都加上x:操作2是将l到r之间的数都开方:操作3是 ...

  4. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  5. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  6. HDU 5828 Rikka with Sequence (线段树)

    Rikka with Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...

  7. hdu 4893 Wow! Such Sequence!(线段树)

    题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...

  8. HDU 6089 Rikka with Terrorist (线段树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左 ...

  9. HDU 5634 Rikka with Phi 线段树

    题意:bc round 73 div1 D 中文题面 分析:注意到10^7之内的数最多phi O(log(n))次就会变成1, 因此可以考虑把一段相同的不为1的数缩成一个点,用平衡树来维护. 每次求p ...

随机推荐

  1. 【设计模式】 模式PK:装饰模式VS适配器模式

    1.概述 装饰模式和适配器模式在通用类图上没有太多的相似点,差别比较大,但是它们的功能有相似的地方:都是包装作用,都是通过委托方式实现其功能.不同点是:装饰模式包装的是自己的兄弟类,隶属于同一个家族( ...

  2. 深入HBase架构解析(一)

    前记 公司内部使用的是MapR版本的Hadoop生态系统,因而从MapR的官网看到了这篇文文章:An In-Depth Look at the HBase Architecture,原本想翻译全文,然 ...

  3. Ubuntu12.04 SVN安装过程

    一.安装SVN和配置SVN 1.安装SVN apt-get install subversion 2.创建SVN目录,项目目录和配置文件目录 mkdir /var/svn mkdir /var/svn ...

  4. apache+svn+ldap集成

    apache+svn搭建方式如下:http://www.cnblogs.com/uglyliu/p/6914056.html SVN和ldap集成,我用的方式只需要更改 /etc/http/conf. ...

  5. python初步学习-pycharm使用

    Pycharm简介 PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成. ...

  6. chrome最小字体12px如何修改

    在html标记样式里加入 <style> html { -webkit-text-size-adjust:none } </style> 这样的方式可以设置chrome字体小于 ...

  7. eCharts_基于eCharts开发的一个多图表页面

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. Java的Integer常量池和String常量池

    1.Integer的常量池 看下面一段代码: package cn.qlq.test; public class ArrayTest { public static void main(String[ ...

  9. 【Python学习笔记】使用Python进行主成分分析

    使用sklearn库中的PCA类进行主成分分析. 导入要用到的库,还没有的直接pip安装就好了. from sklearn.decomposition import PCA import numpy ...

  10. SourceTree 过期,注册导入许可证

    参考这里:SourceTree过期,需要注册导入 SourceTree License 许可证 很详细 补充: 如果在 SourceTree 软件里注册失败,可以在网页注册. 如果其他邮箱不支持,可以 ...