hdu 4027 2011上海赛区网络赛G 线段树 成段平方根 ***

不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了

复制代码
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 using namespace std;
 9 #define MOD 1000000007
10 const int INF=0x3f3f3f3f;
11 const double eps=1e-5;
12 typedef long long ll;
13 #define cl(a) memset(a,0,sizeof(a))
14 #define ts printf("*****\n");
15 #define lson l,mid,rt<<1
16 #define rson mid+1,r,rt<<1|1
17 #define root 1,n,1
18 #define mid ((l+r)>>1)
19 const int MAXN=100100;
20 int n,m,t,Min;
21 ll sum[MAXN<<2];
22 int col[MAXN<<2];
23 void pushup(int rt)
24 {
25     sum[rt]=sum[rt<<1]+sum[rt<<1|1];
26     col[rt]=col[rt<<1]&&col[rt<<1|1];
27 }
28 void build(int l,int r,int rt){
29     col[rt]=0;
30     if(l==r)
31     {
32         scanf("%I64d",&sum[rt]);
33         return;
34     }
35     build(lson);
36     build(rson);
37     pushup(rt);
38 }
39 void update(int L,int R,int l,int r,int rt)
40 {
41     if(l==r)
42     {
43         sum[rt]=sqrt(sum[rt]);
44         if(sum[rt]==1)  col[rt]=1;
45         return;
46     }
47     if(L<=mid&&!col[rt<<1])  update(L,R,lson);
48     if(R>mid&&!col[rt<<1|1]) update(L,R,rson);
49     pushup(rt);
50 }
51 ll query(int L,int R,int l,int r,int rt)
52 {
53     if(l>=L&&r<=R)
54     {
55         return sum[rt];
56     }
57     ll ans=0;
58     if(L<=mid)  ans+=query(L,R,lson);
59     if(R>mid) ans+=query(L,R,rson);
60     return ans;
61 }
62 int main()
63 {
64     int i,j,k;
65     #ifndef ONLINE_JUDGE
66     freopen("1.in","r",stdin);
67     #endif
68 
69     int ca=1;
70     while(scanf("%d",&n)!=EOF)
71     {
72         build(root);
73         int q;
74         scanf("%d",&q);
75         printf("Case #%d:\n",ca++);
76         int s,L,R;
77         while(q--)
78         {
79             scanf("%d%d%d",&s,&L,&R);
80             if(L>R) swap(L,R);
81             if(s==0)
82             {
83                 update(L,R,root);
84             }
85             else
86             {
87                 ll w=query(L,R,root);
88                 printf("%I64d\n",w);
89             }
90         }
91         printf("\n");
92     }
93 }
复制代码

 

posted @   miao_a_miao  阅读(329)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
点击右上角即可分享
微信分享提示