zoukankan      html  css  js  c++  java
  • 【BZOJ1067】降雨量

    1067: [SCOI2007]降雨量

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 4697  Solved: 1241
    [Submit][Status][Discuss]

    Description

      我们常常会说这样的话:“X年是自Y年以来降雨量最多的”。它的含义是X年的降雨量不超过Y年,且对于任意
    Y<Z<X,Z年的降雨量严格小于X年。例如2002,2003,2004和2005年的降雨量分别为4920,5901,2832和3890,
    则可以说“2005年是自2003年以来最多的”,但不能说“2005年是自2002年以来最多的”由于有些年份的降雨量未
    知,有的说法是可能正确也可以不正确的。

    Input

      输入仅一行包含一个正整数n,为已知的数据。以下n行每行两个整数yi和ri,为年份和降雨量,按照年份从小
    到大排列,即yi<yi+1。下一行包含一个正整数m,为询问的次数。以下m行每行包含两个数Y和X,即询问“X年是
    自Y年以来降雨量最多的。”这句话是必真、必假还是“有可能”。

    Output

      对于每一个询问,输出true,false或者maybe。

    Sample Input

    6
    2002 4920
    2003 5901
    2004 2832
    2005 3890
    2007 5609
    2008 3024
    5
    2002 2005
    2003 2005
    2002 2007
    2003 2007
    2005 2008

    Sample Output

    false
    true
    false
    maybe
    false

    HINT

    100%的数据满足:1<=n<=50000, 1<=m<=10000, -10^9<=yi<=10^9, 1<=ri<=10^9

    Source

    POJ 2637 WorstWeather Ever

     solution:

    线段树应该都会写吧 我实在是不想吐槽啥了 挂了n遍实在是不想搞了

    参考hzc的blog:http://blog.csdn.net/huzecong/article/details/8563362

    我挂了x次 具体请搜索restart……

    写不对就重写吧 我是对着hzc的blog完全重写了一遍才过的

    /*To The End Of The Galaxy*/
    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<iomanip>
    #include<stack>
    #include<map>
    #include<set>
    #include<cmath>
    #include<complex>
    #define debug(x) cerr<<#x<<"="<<x<<endl
    #define INF 0x7f7f7f7f
    #define llINF 0x7fffffffffffll
    using namespace std;
    typedef pair<int,int> pii;
    typedef long long ll;
    inline int init()
    {
        int now=0,ju=1;char c;bool flag=false;
        while(1)
        {
            c=getchar();
            if(c=='-')ju=-1;
            else if(c>='0'&&c<='9')
            {
                now=now*10+c-'0';
                flag=true;
            }
            else if(flag)return now*ju;
        }
    }
    inline long long llinit()
    {
        long long now=0,ju=1;char c;bool flag=false;
        while(1)
        {
            c=getchar();
            if(c=='-')ju=-1;
            else if(c>='0'&&c<='9')
            {
                now=now*10+c-'0';
                flag=true;
            }
            else if(flag)return now*ju;
        }
    }
    struct segment
    {
        int l,r,max,min;
    }tree[2000005];
    int id[500005],v[500005];
    int n,m,cnt=0;
    #define lson (now<<1)
    #define rson (now<<1|1)
    #define mid ((l+r)>>1)
    void update(int now)
    {
        tree[now].max=max(tree[lson].max,tree[rson].max);
        tree[now].min=min(tree[lson].min,tree[rson].min);
    }
    void build(int l,int r,int now)
    {
        tree[now].l=l;tree[now].r=r;
        if(l==r)
        {
            tree[now].max=v[l];
            tree[now].min=v[l];
        }
        else
        {
            build(l,mid,lson);
            build(mid+1,r,rson);
            update(now);
        }
    }
    int querymin(int l,int r,int x,int y,int now)
    {
        if(x>y)return -INF;
        if(l==x&&r==y)
        {
            return tree[now].min;
        }
        else
        {
            if(y<=mid)return querymin(l,mid,x,y,lson);
            else if(x>mid)return querymin(mid+1,r,x,y,rson);
            else return min(querymin(l,mid,x,mid,lson),querymin(mid+1,r,mid+1,y,rson));
        }
    }
    int querymax(int l,int r,int x,int y,int now)
    {
        if(x>y)return -INF;
        if(l==x&&r==y)
        {
            return tree[now].max;
        }
        else
        {
            if(y<=mid)return querymax(l,mid,x,y,lson);
            else if(x>mid)return querymax(mid+1,r,x,y,rson);
            else return max(querymax(l,mid,x,mid,lson),querymax(mid+1,r,mid+1,y,rson));
        }
    }
    int main()
    {
        int x,y,q;
        n=init();
        for(int i=1;i<=n;i++)
        {
            id[i]=init();v[i]=init();
        }
        cnt=n;
        q=init();
        build(1,n,1);
        int l,r;
        int judger;//0 maybe 1 true 2 false
        bool lx,rx;
        while(q--)
        {
            x=init();y=init();
            l=lower_bound(id+1,id+1+n,x)-id;
            r=lower_bound(id+1,id+1+n,y)-id;
            lx=l<=n&&id[l]==x;
            rx=r<=n&&id[r]==y;
            if(!rx)r--;
            if(lx)
            {
                if(rx)
                {
                    m=querymax(1,n,l+1,r-1,1);
                    if(v[l]<v[r])
                    {
                        judger=0;
                    }
                    else
                    {
                        if(m<v[r])
                        {
                            if(r-l==y-x)
                            {
                                judger=1;
                            }
                            else judger=-1;
                        }
                        else judger=0;
                    }
                }
                else
                {
                    m=querymax(1,n,l+1,r,1);
                    if(m<v[l])
                    {
                        judger=-1;
                    }
                    else judger=0;
                }
            }
            else
            {
                if(rx)
                {
                    m=querymax(1,n,l,r-1,1);
                    if(m<v[r])
                    {
                        judger=-1;
                    }
                    else judger=0;
                }
                else judger=-1;
            }
            if(judger==-1)
            {
                printf("maybe
    ");
            }
            else if(judger==1)
            {
                printf("true
    ");
            }
            else printf("false
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    智能实验室-杀马(Defendio) 3.0.0.670 新春贺岁版
    智能实验室-全能优化(Guardio) 4.0.0.680 beta 9
    解密:骗人的所谓“开放六位 QQ 号码免费申请”
    智能实验室-全能优化(Guardio) 4.0.0.630 beta 3
    智能实验室-全能优化(Guardio) 4.0.0.650 beta 6
    智能实验室-杀马(Defendio) 3.0.0.651 beta 9
    智能实验室-杀马(Defendio) 3.0.0.632 beta 8
    智能实验室-全能优化(Guardio) 4.0.0.691 beta 11
    智能实验室-全能优化(Guardio) 4.0.0.620 beta 2
    智能实验室-全能优化(Guardio) 4.0.0.685 beta 10
  • 原文地址:https://www.cnblogs.com/redwind/p/6545090.html
Copyright © 2011-2022 走看看