Can you answer these queries? HDU - 4027
给一串数字,再给一串操作,操作分两种,第一种是求u,v区间之和,第二种是把u,v区间内所有数变成其平方根,所给数字不超过long long
暴力更新,因为2的63次方sqrt不到10次就可以变成1,所以更新的时候判断其区间内是否都为一,都为1则不更新,否则往下更新
恶心的是题目给的u,v不保证u一定小于v,而且没个cas之后要加个空行,特意卡输出格式。
//#if 0
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <math.h>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <time.h>
#include <set>
#include <list>
#include <iostream>
#define ll long long
#define ull unsigned long long
#define cls(x) memset(x,0,sizeof(x))
#define clslow(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
//typedef long long ll;
using namespace std;
const int maxn=1e5+100;
const int mod=1e9+7;ll a[maxn],ans[maxn<<2];void Push_up(int rt)
{ans[rt]=ans[rt<<1]+ans[rt<<1|1];
}void Build(int l,int r,int rt)
{if(l==r){ans[rt]=a[l];return;}int mid=(r+l)>>1;Build(l,mid,rt<<1);Build(mid+1,r,rt<<1|1);Push_up(rt);
}void Update(int L,int R,int l,int r,int rt)
{if(L<=l && r<=R && r-l+1==ans[rt]){return;}if(l==r){ans[rt]=(ll)sqrt(ans[rt]);return;}int mid=(l+r)>>1;if(L<=mid)Update(L,R,l,mid,rt<<1);if(R>mid)Update(L,R,mid+1,r,rt<<1|1);Push_up(rt);
}ll Query(int L,int R,int l,int r,int rt)
{if(L<=l && r<=R){return ans[rt];}ll ANS=0;int mid=(l+r)>>1;if(L<=mid)ANS+=Query(L,R,l,mid,rt<<1);if(R>mid)ANS+=Query(L,R,mid+1,r,rt<<1|1);return ANS;
}int main()
{// freopen("in.txt", "r", stdin);int n,cas=1;while(~scanf("%d",&n)){for(int i=1;i<=n;i++)scanf("%lld",&a[i]);int m;scanf("%d",&m);Build(1,n,1);printf("Case #%d:\n",cas++);while(m--){int t,u,v;scanf("%d%d%d",&t,&u,&v);if(u>v)swap(u,v);if(t==0){Update(u,v,1,n,1);}else{printf("%lld\n",Query(u,v,1,n,1));}}printf("\n");}return 0;
}
Can you answer these queries? HDU - 4027相关推荐
- HDU 4027 Can you answer these queries?(线段树/区间不等更新)
传送门 Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/6576 ...
- HDU 1027 G - Can you answer these queries?
http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Time Limit: 4000/2000 M ...
- HDU - 4027
Can you answer these queries? 链 接 链接 链接 HDU - 4027 题 目 是 区 间 修 改 区 间 查 询 , 但 是 区 间 开 根 号 , 求 区 间 和 题 ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- 线性代数四之动态DP(广义矩阵加速)——Can you answer these queries III,保卫王国
动态DP--广义矩阵加速 SP1716 GSS3 - Can you answer these queries III description solution code [NOIP2018 提高组] ...
- SPOJ GSS2 Can you answer these queries II (线段树离线) - xgtao -
Can you answer these queries II 这是一道线段树的题目,维护历史版本,给出N(<=100000)个数字(-100000<=x<=100000),要求求出 ...
- GSS2 - Can you answer these queries II
GSS2 - Can you answer these queries II 题意: 给你1e51e51e5 的序列,每次询问区间l到rl到rl到r,每个相同的数只算一次的最大子段和. 思路: 乍一眼 ...
- hdu - 4027 Can you answer these queries?
http://acm.hdu.edu.cn/showproblem.php?pid=4027 /** * 题意:给你n个数,对这些数进行操作,有m组操作 * q == 0 [x,y]区间内的每个数开方 ...
- hdu 4027 Can you answer these queries?
http://acm.hdu.edu.cn/showproblem.php?pid=4027 [更新区间,查询区间]的线段树,必须抓住修改6次以后每个数必然会变成1,然后以后的修改都将不起作用,在此之 ...
最新文章
- app怎么嵌套vue页面_app内嵌vue单页面应用的一些坑
- android设备不自带sqlite3问题(sqlite3 not found)
- python多边形裁剪
- Executors.newFixedThreadPool和ArrayBlockingQueue一点使用心得
- 打包文档_苏教版小学数学16年级全十二册教案Word文档打包下载
- html5表格树,利用ztree实现树形表格
- python定时爬取数据_python实现scrapy爬虫每天定时抓取数据的示例代码
- leetcode力扣406. 根据身高重建队列
- 淘宝推荐系统简介分享总结
- Axure RP9授权码
- Java解压ZIP、RAR文件
- 手机图片怎么压缩,简单的压缩方法
- 如何使用Google的Draco项目
- 英特尔最新超级计算机,全球超级计算机500强三分之二使用英特尔的处理器
- 高中必备学习软件_高中党必备高效学习软件
- PostGIS 结合Openlayers以及Geoserver实现最短路径分析(二)
- RTC电路锂电池耗电过快的问题
- est.java 2 错误 找不到符号_生物信息学复习题
- Android之粗仿微信6.0——微信分界面
- UVa 11536 最短子序列(Smallest Sub-Array)
热门文章
- 【Pytorch】Label Smoothing
- 华中科技大学校长李培根的演讲
- 瞰源 | 别逗了,同学;开源不是点赞送礼~
- 六月集训(第30天) —— 拓扑排序
- php mysql 论坛 源码_LNMP架构的搭建(linux+nginx+mysql+php源码安装 )+Discuz论坛的搭建...
- mysql 结果字段截取_mysql字段截取(转)
- C++课程设计之通讯录管理系统
- Twitter 被裁员工的集体诉讼遭法官驳回!
- 下一个倒下的会不会是华为
- Python毫秒准换为秒