• 【bzoj3211】花神游历各国


    不知道花神究竟是哪位dalao,但是我还是想缅怀下菊花大爷……

    提交:http://www.lydsy.com/JudgeOnline/problem.php?id=3211

    又一个区间开根号题,不过这个无修改的比较简单,可以YY一下,一个区间开根号,开着开着就成了0或者1,维护下就好。

    当然jiry的那题带个修改烦一点,不过也还好。

    带修改的提交地址:http://uoj.ac/problem/228

    因为是之前写的现在先不写blog了,等有空再写……

    放下代码地址:http://uoj.ac/submission/139463(欢迎hack)

     1 #include<bits/stdc++.h>
     2 #define N 100005
     3 #define lson (o<<1)
     4 #define rson (o<<1|1)
     5 using namespace std;
     6 typedef long long ll;
     7 ll a[N];int n,m;
     8 struct Segment_Tree{
     9     ll sumv[N<<2];int setv[N<<2];
    10     inline void pushup(int o){
    11         sumv[o]=sumv[lson]+sumv[rson];
    12         setv[o]=setv[lson]&setv[rson];
    13     }
    14     void build(int o,int l,int r){
    15         if(l==r){
    16             sumv[o]=a[l];if(a[l]==0||a[l]==1)setv[o]=1;
    17             return;
    18         }
    19         int mid=(l+r)>>1;
    20         build(lson,l,mid);build(rson,mid+1,r);
    21         pushup(o);
    22     }
    23     void change(int o,int l,int r,int ql,int qr){
    24         if(setv[o])return;
    25         if(l==r){
    26             sumv[o]=(ll)sqrt(sumv[o]);
    27             if(sumv[o]==1||sumv[o]==0)setv[o]=1;
    28             return;
    29         }
    30         int mid=(l+r)>>1;
    31         if(ql<=mid)change(lson,l,mid,ql,qr);
    32         if(qr>mid)change(rson,mid+1,r,ql,qr);
    33         pushup(o);
    34     }
    35     ll querysum(int o,int l,int r,int ql,int qr){
    36         if(ql<=l&&r<=qr)return sumv[o];
    37         int mid=(l+r)>>1;ll ans=0;
    38         if(ql<=mid)ans+=querysum(lson,l,mid,ql,qr);
    39         if(qr>mid)ans+=querysum(rson,mid+1,r,ql,qr);
    40         return ans;
    41     }
    42 }T;
    43 inline ll read(){
    44     ll f=1,x=0;char ch;
    45     do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    46     do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    47     return f*x;
    48 }
    49 int main(){
    50     n=read();
    51     for(int i=1;i<=n;i++)a[i]=read();
    52     T.build(1,1,n);
    53     m=read();
    54     while(m--){
    55         int opt=read(),x=read(),y=read();
    56         if(x>y)swap(x,y);
    57         if(opt==2)T.change(1,1,n,x,y);
    58         else printf("%lld
    ",T.querysum(1,1,n,x,y));
    59     }
    60     return 0;
    61 }
    花神游历各国
  • 相关阅读:
    洛谷1069 细胞分裂
    洛谷1050 循环
    CF Good Bye 2018
    洛谷1043 数字游戏
    洛谷1041 传染病控制
    洛谷1040 加分二叉树
    洛谷1039 侦探推理
    洛谷1038 神经网络
    设计模式的区别
    volatile和synchronized与lock的理解
  • 原文地址:https://www.cnblogs.com/zcysky/p/6843123.html
Copyright © 2020-2023  润新知