zoukankan      html  css  js  c++  java
  • 忠诚

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    const long long  maxn=5e5+5;
    
    long long  a[maxn];
    
    struct Segment{
        
        long long  l,r;
        long long  sum;
        long long  tag;
        Segment *lef,*rig;
        
        Segment(const long long  L,const long long  R )
        {
            l=L;r=R;
            tag=0;
            if(l != r)
            {
                int mid=l+r>>1;//这nm对了就离谱 
                lef=new Segment(l,mid);
                rig=new Segment(mid+1,r);
                sum=min(lef->sum,rig->sum);
                tag=0;
            }
            else{
                lef=rig=NULL;
                sum=a[l];
            }
        }
    /*    
        inline void maketag(){
            sum=(r-l+1)-sum;
            tag^=1;
        }
    */
    /*    
        void spread()
        {
    //        if(lef == NULL) lef=new Segment(l,mid);
    //        if(rig == NULL) rig =new Segment(mid+1,r);
            if(tag==0) return;
            else {
                lef->maketag();
                rig->maketag();
                tag=0;
            }
        }    
    */
        inline bool Out(const long long  L,const long long  R) { return (R<l || r<L ) ;}
    
    /*    void change(long long  L,long long  R)
        {
            if(L<=l && r<=R){
                maketag();
            }
            else {
                if(Out(L,R)) return ;
                else{
                spread();
                lef->change(L,R);
                rig->change(L,R);
                sum=lef->sum+rig->sum;
                } 
                
            }
        }
        
    */    
        long long  ask(long long  L,long long  R)
        {
            if(L<=l && r<=R) return sum;
            else {
                if(Out(L,R)) return 1<<30;
                else{
                return  min(lef->ask(L,R),rig->ask(L,R));
                
                } 
                
            }
        }
        
    };
    
    Segment *root;
    
    int  main(void)
    {
        long long  n,m,q;
        
        ios_base::sync_with_stdio(false);
        cout.tie(NULL);
        cin.tie(NULL);
        
        cin>>n>>m;
        
        for(int i=1;i<=n;i++)
        cin>>a[i];
        
        root=new Segment(1,n);
        
        for(long long  i=1;i<=m;i++)
        {
            long long  x,y,z;
            cin>>x>>y;
        
            cout<<root->ask(x,y)<<" ";
        }
        return 0;
    }

    来自lsq's code

  • 相关阅读:
    mysql资料
    MySQL启动与关闭
    poj 2778 DNA Sequence
    poj 1625 Censored!
    zoj 3228 Searching the String
    hdu 4605 Magic Ball Game
    hdu 4610 Cards
    SGU 439 A Secret Book
    NOI2013
    NOI2014
  • 原文地址:https://www.cnblogs.com/dairuizhe/p/13246287.html
Copyright © 2011-2022 走看看