bzoj1067

题意:

给你下雨量,让你判断每一句话是否正确

题解:

线段树

用来维护判断

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=400005;
struct seg
{
    int max;
}tree[N];
int n,m,x[N],y[N],sum[N];
void build(int rt,int L,int R)
{
    if (L==R)
     {
        tree[rt].max=y[L];
        return;
     }
    int mid=(L+R)>>1;
    build(rt<<1,L,mid);
    build((rt<<1)+1,mid+1,R);
    tree[rt].max=max(tree[rt<<1].max,tree[(rt<<1)+1].max);
}
int query(int rt,int L,int R,int QL,int QR)
{
    if (QL>R||QR<L) return -2e9;
    if (QL<=L&&QR>=R) return tree[rt].max;
    int mid=(L+R)>>1;
    return max(query(rt<<1,L,mid,QL,QR),
    query((rt<<1)+1,mid+1,R,QL,QR));
}
int find(int X)
{
    int L=1,R=n,mid;
    while (L<=R)
     {
        mid=(L+R)>>1;
        if (x[mid]==X) return mid;
        if (x[mid]>X) R=mid-1;
        if (x[mid]<X) L=mid+1;
     }
    return -1;
}
int find_2(int X)
{
    int L=1,R=n,mid,res;
    while (L<=R)
     {
        mid=(L+R)>>1;
        if (x[mid]>X) res=mid,R=mid-1;
        else L=mid+1;
     }
    return res;
}
int find_3(int X)
{
    int L=1,R=n,mid,res;
    while (L<=R)
     {
        mid=(L+R)>>1;
        if (x[mid]<X) res=mid,L=mid+1;
        else R=mid-1;
     }
    return res;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
    build(1,1,n);
    scanf("%d",&m);
    for (int i=1,x1,x2,bh1,bh2;i<=m;i++)
     {
        scanf("%d%d",&x1,&x2);
        if (!(x1<x2))
         {
            puts("false");
            continue;
         }
        bh1=find(x1),bh2=find(x2);
        if (bh1==-1 && bh2==-1)
         {
            puts("maybe");
            continue;
          }
        if (bh2==-1)
         {
            bh2=find_3(x2);
            if (bh1+1>bh2||query(1,1,n,bh1+1,bh2)<y[bh1])
             puts("maybe");
            else puts("false");
            continue;
         }
        if (bh1==-1)
         {
            bh1=find_2(x1);
            if (bh1>bh2-1||query(1,1,n,bh1,bh2-1)<y[bh2])puts("maybe");
            else puts("false");
            continue;
         }
        if (!(y[bh1]>=y[bh2]))
         {
            puts("false");
            continue;
         }
        if (bh1+1>bh2-1||query(1,1,n,bh1+1,bh2-1)<y[bh2])
        if (x2-x1==bh2-bh1)puts("true");
        else puts("maybe");
        else puts("false");
     }
    return 0;
}

 

转载于:https://www.cnblogs.com/xuanyiming/p/8446404.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值