• BZOJ 1067 & Interval_Tree


    1067: [SCOI2007]降雨量
    Time Limit: 1 Sec Memory Limit: 162 MB
    Submit: 3099 Solved: 800
    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

    SOL

    裸的线段树,在离散化之后对于每个询问x,y我们在x后查询最大值判断位置、值是否相等即可。(我难得地非常...细心地判断了位置...就没有看到一个人跟我这么写传一个struct的...然而我tm就是wa了有什么办法...
    对于maybe的判断,我用一个bool判断当年与上一年的信息是否是相连的,在线段树中用&维护与查询即可。(然而我tm就是wa了有什么办法...
    对拍了好多次,有许多数据黄学长都是错的...然而他就是a了有什么办法(难道是我对题意的理解有问题QAQ...
    

    code

    虽然没有a掉...但我觉得我写得已经很...perfect了...
    
    /*==========================================================================
    # Last modified: 2016-02-08 22:15
    # Filename: 1067.cpp
    # Description: 
    ==========================================================================*/
    #define me AcrossTheSky 
    #include <cstdio> 
    #include <cmath> 
    #include <ctime> 
    #include <string> 
    #include <cstring> 
    #include <cstdlib> 
    #include <iostream> 
    #include <algorithm> 
    
    #include <set> 
    #include <map> 
    #include <stack> 
    #include <queue> 
    #include <vector> 
    #define lowbit(x) (x)&(-x) 
    #define INF 1070000000 
    #define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++) 
    #define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
    #define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
    #define ls(a,b) (((a)+(b)) << 1) 
    #define rs(a,b) (((a)+(b)) >> 1) 
    #define maxn 500005
    using namespace std; 
    typedef long long ll; 
    typedef unsigned long long ull; 
    /*==================split line==================*/ 
    struct Infor{
        int maxx,pos;
        bool mark;
    };
    int v[maxn*4];
    bool mark[maxn*4];
    int pos[maxn*4],rain[maxn],year[maxn];
    int L,R;
    bool bj[maxn];
    map<int,int>M;
    void build_tree(int node,int l,int r){
        if (l==r){
            v[node]=rain[l];
            mark[node]=bj[l];
            pos[node]=l;
            return;
        }
        int mid=rs(l,r),lc=ls(node,0),rc=lc|1;
        build_tree(lc,l,mid); build_tree(rc,mid+1,r);
        v[node]=max(v[lc],v[rc]);
        if (v[lc]>=v[rc]) pos[node]=pos[lc]; else pos[node]=pos[rc];
        mark[node]=mark[lc]&mark[rc];
    }
    Infor query(int node,int l,int r){
        if (L<=l && r<=R){
            Infor x;
            x.maxx=v[node];
            x.mark=mark[node];
            x.pos=pos[node];
            return x;
        }
        int mid=rs(l,r),lc=ls(node,0),rc=lc|1;
        Infor ans; ans.maxx=-INF; ans.mark=true;
        if (L<=mid) ans=query(lc,l,mid);
        if (R>mid){
            Infor t=query(rc,mid+1,r);
            if (t.maxx>ans.maxx) ans.maxx=t.maxx,ans.pos=t.pos,ans.mark&=t.mark;
        }
        return ans;
    }
    int main(){
        freopen("a.in","r",stdin);
        freopen("tmp.out","w",stdout);
        int n; cin >> n;
        memset(mark,true,sizeof(mark));
        memset(bj,true,sizeof(bj));
        FORP(i,1,n){
            scanf("%d%d",&year[i],&rain[i]);
            if (i!=1 && year[i]!=year[i-1]+1) bj[i]=false;
            M[year[i]]=i;
        }
        //FORP(i,1,n) printf("%d ",M[year[i]]);
        build_tree(1,1,n);
        int m; cin >> m;
        FORP(i,1,m){
            scanf("%d%d",&L,&R);
            L=M[L]; R=M[R];
            //if (rain[R]>rain[L]) {printf("false
    "); continue;}
            L++;
            Infor x=query(1,1,n); 
            if (x.maxx!=rain[R] || x.pos!=R) {printf("false
    "); continue;}
            if (x.maxx==rain[R] && x.pos==R && !x.mark) {
                printf("maybe
    "); continue;
            }
            else printf("true
    ");
        }
    } 
    Sometimes it s the very people who no one imagines anything of. who do the things that no one can imagine.
  • 相关阅读:
    Linux如何自动获取IP地址
    jq操作select集合
    UDP and TCP
    IPv6
    DHCP, NAT
    队列之顺序存储实现
    ARP, Fragmentation and Reassembly
    Classless Interdomain Routing (CIDR)
    Subnet Routing Examples
    Subnetting
  • 原文地址:https://www.cnblogs.com/YCuangWhen/p/5188077.html
Copyright © 2020-2023  润新知