Can you answer these queries?
链
接
链接
链接 HDU - 4027
题
目
是
区
间
修
改
区
间
查
询
,
但
是
区
间
开
根
号
,
求
区
间
和
题目是区间修改区间查询,但是区间开根号,求区间和
题目是区间修改区间查询,但是区间开根号,求区间和
本
来
想
用
懒
标
记
,
但
好
像
不
太
方
便
,
但
我
们
关
注
下
数
据
特
点
本来想用懒标记,但好像不太方便,但我们关注下数据特点
本来想用懒标记,但好像不太方便,但我们关注下数据特点
最
大
2
e
64
次
方
,
也
就
是
64
次
开
根
号
就
成
为
了
1
然
后
就
不
再
改
变
最大2e64次方,也就是64次开根号就成为了1然后就不再改变
最大2e64次方,也就是64次开根号就成为了1然后就不再改变
所
以
我
们
区
间
修
改
可
以
改
为
单
点
修
改
,
然
后
加
一
个
类
似
剪
枝
的
操
作
就
可
以
不
超
时
了
所以我们区间修改可以改为单点修改,然后加一个类似剪枝的操作就可以不超时了
所以我们区间修改可以改为单点修改,然后加一个类似剪枝的操作就可以不超时了
代 码 代码 代码
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
struct node{
int l, r;
ll sum;
}tr[N << 2];
int n, m;
ll arr[N];
void pushup(int u)
{
tr[u].sum = tr[u<<1].sum + tr[u<<1|1].sum;
}
void build(int u, int l, int r)
{
tr[u] = {l, r, 0};
if(l == r) {
tr[u].sum = arr[l];
return ;
}
int mid = l + r >> 1;
build(u<<1, l, mid);
build(u<<1|1, mid+1, r);
pushup(u);
}
void modify(int u,int l,int r)
{
if(tr[u].sum == (tr[u].r - tr[u].l + 1))
{
return;
}
if(tr[u].l == tr[u].r)
{
tr[u].sum = sqrt(tr[u].sum);
return ;
}
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) modify(u<<1, l, r);
if(r > mid) modify(u<<1|1, l, r);
pushup(u);
}
ll query(int u,int l,int r)
{
//if(tr[u].r < l || tr[u].l > r) return 0;
if(tr[u].l >= l && tr[u].r <= r)
{
return tr[u].sum;
}
ll res = 0;
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid)
{
res += query(u<<1, l, r);
}
if(r > mid) res += query(u<<1|1, l, r);
return res;
}
int main()
{
int idx = 0;
while(~scanf("%d", &n))
{
for(int i = 1; i <= n; i ++)
{
scanf("%lld", &arr[i]);
}
scanf("%d", &m);
build(1, 1, n);
printf("Case #%d:\n", ++idx);
while(m--)
{
int op, x, y;
scanf("%d %d %d", &op, &x, &y);
if(x > y) x ^= y ^= x ^= y;
if(op == 0)
{
modify(1, x, y);
}
else
{
ll res = query(1, x, y);
printf("%lld\n", res);
}
}
puts("");
}
return 0;
}