Can you answer these queries? HDU - 4027 有点坑
2024-09-03 03:44:03
#include<iostream>
#include<cstring>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
ll a[N];
int n,m;
int op,l,r;
struct node
{
ll l,r;
ll sum;
}tr[N*];
void build(int root,int l, int r)
{
tr[root]={l,r};
tr[root].sum=;
if(l==r)
{
tr[root].sum=a[l];
return;
}
int mid=l+r>>;
build(root<<,l,mid);
build(root<<|,mid+,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
void update(int root,int l,int r)
{
if(l>tr[root].r||tr[root].l>r)
return;
if (tr[root].sum==(tr[root].r-tr[root].l + ))
return;
if (tr[root].l==tr[root].r)
{
tr[root].sum=sqrt(tr[root].sum);
return;
}
int mid=tr[root].l+tr[root].r>>;
update(root<<,l,r);
update(root<<|,l,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
ll Query(int root,int l,int r)
{
if (l>tr[root].r||tr[root].l>r)
return ;
if (l<=tr[root].l&&tr[root].r<=r)
return tr[root].sum;
int mid=tr[root].l+tr[root].r>>;
ll res=;
res+=Query(root<<,l,r);
res+=Query(root<<|,l,r);
return res;
}
int main()
{
int cnt=;
while(~scanf("%d",&n))
{
printf("Case #%d:\n",++cnt);
for (int i=;i<=n;i++)
scanf("%lld",&a[i]);
scanf("%d",&m);
build(,,n);
while (m--)
{
scanf("%d%d%d",&op,&l,&r);
if(l>r)
swap(l,r);
if(op==)
update(,l,r);
else
printf("%lld\n",Query(,l,r));
}
printf("\n");
}
return ;
}
最新文章
- C#操作SQLite数据库
- cairo-1.14.6 static compiler msys mingw32
- Could not load file or assembly &#39;System.Core, Version=2.0.5.0 和autofac冲突的问题
- linux下安装openssh-server
- Java基础之访问文件与目录——测试文件或目录的路径(TryPath)
- (Java)《head first java》值得Java或面向对象基础的新手看。
- Python引用传值总结
- OC基础1:一些基本概念
- [计算机基础]关于实体( Entity )和模型( Model )
- 媲美jQuery的JS框架----AngularJS(二)
- 护航者,腾讯云: 2017年度游戏行业DDoS态势报告—回溯与前瞻
- Redis调用的流程(新手使用)
- January 19th, 2018 Week 3rd Friday
- IO model
- SCOPE_IDENTITY的用法【转载】
- Fibonacci(矩阵)
- SpringCloud服务消费者第一次调用出现超时问题的解决方案
- 漫谈NIO(2)之Java的NIO
- KETTLE元数据表
- 深入理解javascript作用域系列第五篇
热门文章
- 16、ISDN
- Asp.net core 2.x/3.x 的 Globalization 和 localization 的使用 (一) 使用方法
- Codeforces 924 A Tritonic Iridescence(暴力集合交集、相等)
- SpringBoot学习笔记 文件访问映射
- NR / 5G - MAC Overview
- Day5前端学习之路——盒模型和浮动
- Python性能优化方案
- OpenResty 在马蜂窝广告监测中的应用
- 0x01 C语言-编写第一个hello world
- markdown语法链接新页面打开