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. web版canvas做飞机大战游戏 总结

    唠唠:两天的时间跟着做了个飞机大战的游戏,感觉做游戏挺好的.说是用html5做,发现全都是js.说js里一切皆为对象,写的最多的还是函数,都是函数调用.对这两天的代码做个总结,希望路过的大神指点一下, ...

  2. mysql数据库cmd直接登录

    找到mysql的安装路径: 将该路径配置到环境变量中: win+R代开dos窗口:输入mysql -uroot -p回车,输入密码.

  3. 【Nginx】不改系统源代码的情况下,动态网站离线缓存方案

    背景: 公司的一套系统,由前端.界面.服务层.大数据开发平架等多层组成,每一层被划分为多个模块,每个模块会依赖若干组建.由于公司的这套系统是部署在内网环境中的,现在需要拿出去给客户演示,用一个笔记本装 ...

  4. ios应用里面进入app store 下载界面

    转自:http://blog.csdn.net/diyagoanyhacker/article/details/6654838 在IOS应用里直接打开app store 评论页面的方法: [[UIAp ...

  5. Vuejs - 工欲善其事必先利其器

    既然是实战,怎离不开项目开发的环境呢?先给大家推荐下我的个人开发环境: 硬件设备:Mac OSX编译器:Visual Studio Code命令行工具:iTerm2调试工具:Chrome Dev to ...

  6. 八大疯狂的HTML5 Canvas及WebGL动画效果——8 CRAZY ANIMATIONS WITH WEBGL AND HTML5 CANVAS【收藏】

    HTML5, WebGL and Javascript have changed the way animation used to be. Past few years, we can only a ...

  7. linux 3389连接工具Rdesktop

    简单使用 工作机换成战斗机了,改用ubuntu,原来的windows7上东西笔记多,还不想重装.用rdesktop来远程连接windows: sudo apt-get install rdesktop ...

  8. Linux 入门记录:四、Linux 系统常用命令

    一.日期时间 命令 date 查看.设置当前系统时间: date -u 格林威治时间 date %Y-%m-%d 显示格式化的时间 date -s "23:00" 使用 -s 参数 ...

  9. BZOJ 4241: 历史研究——莫队 二叉堆

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4241 题意:N个int范围内的数,M次询问一个区间最大的(数字*出现次数)(加权众数),可以 ...

  10. 2015多校第6场 HDU 5355 Cake 贪心,暴力DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给你n个尺寸大小分别为1,2,3,…,n的蛋糕,要求你分成m份,要求每份中所有蛋糕的大小之 ...