zoukankan      html  css  js  c++  java
  • 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("*****
    ");
    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:
    ",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
    ",w);
    89             }
    90         }
    91         printf("
    ");
    92     }
    93 }
  • 相关阅读:
    业余草双因素认证(2FA)教程
    业余草网站热门关键字
    微博爬虫“免登录”技巧详解及 Java 实现(业余草的博客)
    业余草通告CSDN博客用户zhang__ao非法转载文章的公告
    CODE大全给你推荐几个免费的leapftp 注册码
    业余草最新热门博客推荐
    莫比乌斯反演
    P5091 【模板】欧拉定理
    LaTeX Test
    P2742 [USACO5.1]圈奶牛Fencing the Cows /【模板】二维凸包
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4689524.html
Copyright © 2011-2022 走看看